Skip to content

prqlc watch leaves a Jinja placeholder before digits and quotes Jinja expressions on Snowflake and Oracle #6562

Open

Description

@prql-bot

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') }}

Actual:

SELECT
  *
FROM
  "orders"
WHERE
  "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.

Found by the 2026-11-16 nightly survey.

Activity

  1. prql-bot commented on Nov 16, 2026

    @prql-bot
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions