Enabling Jinja syntax support in SQL files in PyCharm

It turns out that you can add Jinja syntax support for dbt model files (.sql) and yaml files in PyCharm Professional Edition or other paid JetBrains products that have multi-language support (Sorry DataGrip users). Here’s how to do it.

Disclaimers

  1. Unfortunately this is not available in the Community Edition of PyCharm.
  2. There is currently a bug in JetBrains IDE that shows a valid SQL with Jinja as having syntax errors if a SQL Dialect is selected to something other than “Generic SQL” (e.g Snowflake) Link to ticket. The workaround is to either set the global or project SQL Dialect setting under Languages & Frameworks to “Generic SQL”.
  3. This is not possible to do in DataGrip

Steps

  1. Preferences > Languages and Frameworks > Template Languages.
  2. Select “Jinja2” for the Template Language dropdown at the top,
  3. Click on the “+” icon to add SQL (and YAML) to the list. Hit Apply or OK and you are done!

Screen Shot 2021-05-14 at 9.04.49 AM

4 Likes

I just recently rolled out a dbt workstation environment to a team of 15 and I have been asked if this sort of configuration is possible using VSCode. The VSCode python extension behaves properly and locates the dbt virtualenv, but I ly by manually initiating the extension. Since it is only set to auto initialize on .py files…not .sql

Does anyone know if this is possible in VSCode?

Re VS Code you might want to check this out to see if it suits your use case.

1 Like

Thanks, I will take a look at it.

I’ve just commented on the ticket you raised as it has been conflated with the DataGrip ticket and flagged as a duplicate which it patently isn’t.