You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
prqlc watch leaves a Jinja placeholder before digits and quotes Jinja expressions on Snowflake and Oracle #6562
prqlc watch (the only command that runs the Jinja pre/post-processing in cli/jinja.rs) produces wrong SQL in two cases. Both come from how a Jinja expression is stood in for during compilation: pre_process replaces it with an identifier-like anchor _jinja_<n>, the compiler treats that anchor as an ordinary identifier, and post_process finds anchors in the SQL with the regex _jinja_\d+.
1. A Jinja expression followed by digits leaves the anchor in the output
a.prql:
from {{ ref('orders') }}2024
Actual a.sql:
SELECT*FROM
_jinja_02024
Expected: {{ ref('orders') }}2024.
The anchor _jinja_0 runs into the following digits, the regex then matches _jinja_02024, the map has no such key, and unwrap_or(&anchor_id) writes the anchor through unchanged.
2. On always-quoting targets the Jinja expression lands inside identifier quotes
Snowflake and Oracle use IdentQuotingStyle::AlwaysQuoted (Snowflake, Oracle), so the anchor is emitted as "_jinja_0" and the substitution happens inside the quotes:
prql target:sql.snowflake
from orders
filter amount > {{ var('min') }}
prql target:sql.snowflake / from {{ ref('orders') }} likewise gives FROM "{{ ref('orders') }}", and sql.oracle behaves the same. Expected: the Jinja expression unquoted ("amount" > {{ var('min') }}, FROM {{ ref('orders') }}), as it already is on the generic target.
Once dbt renders those templates the result is a quoted identifier containing the rendered text (a column named after the value, or a relation name wrapped in an extra pair of quotes).
Reproduction
Put the .prql files in a directory and run prqlc watch --no-signature <dir>; the initial pass writes the .sql files next to them (stop it with Ctrl-C / timeout). Reproduced on main at a03bf97.
Not verified: the downstream effect in dbt/Snowflake after rendering was not run; only the SQL prqlc watch writes was checked.
Both cases are fixed in #6567, with CI green on its head (c6a5a522). It's waiting on a maintainer to review and merge.
Anchors now end with _ (_jinja_0_), so digits after an interpolation can't merge into the anchor's id. from {{ ref('orders') }}2024 now gives FROM {{ ref('orders') }}2024.
post_process drops identifier quotes that enclose exactly one anchor. On Snowflake and Oracle this gives FROM {{ ref('orders') }} and "amount" > {{ var('min') }}. Single-quoted string literals keep their quotes.
New tests in cli/jinja.rs run the full pre-process → compile → post-process path, and the digit and quoting tests failed before the change. One case the PR leaves alone: on Snowflake and Oracle, an interpolation glued to other text in a single identifier ({{ ref('orders') }}2024) still comes out as one quoted identifier.
Activity
prql-bot commentedon Nov 16, 2026
Both cases are fixed in #6567, with CI green on its head (
c6a5a522). It's waiting on a maintainer to review and merge._(_jinja_0_), so digits after an interpolation can't merge into the anchor's id.from {{ ref('orders') }}2024now givesFROM {{ ref('orders') }}2024.post_processdrops identifier quotes that enclose exactly one anchor. On Snowflake and Oracle this givesFROM {{ ref('orders') }}and"amount" > {{ var('min') }}. Single-quoted string literals keep their quotes.New tests in
cli/jinja.rsrun the full pre-process → compile → post-process path, and the digit and quoting tests failed before the change. One case the PR leaves alone: on Snowflake and Oracle, an interpolation glued to other text in a single identifier ({{ ref('orders') }}2024) still comes out as one quoted identifier.