Skip to content

Feature Request: Support DuckDB 2.0 $variable syntax in DuckDB dialect #1010

Closed

Description

@gltjk

Describe the Feature

DuckDB 2.0 introduced a $variable shorthand syntax for referencing session variables (equivalent to getvariable('variable')). See official docs: https://duckdb.org/docs/2.0/sql/statements/set_variable

Example:

SET VARIABLE my_var = 30;
SELECT 20 + $my_var AS total;

Currently, when using the duckdb dialect in SQL Formatter, this produces a parse error:

Parse error: Unexpected "$my_var AS" at line 2 column 13.
SQL dialect used: "duckdb".

The formatter should recognize $variable_name as a valid expression in the DuckDB dialect, the same way it already handles positional parameters like $1.

Why do you want this feature?

  • $variable is an official DuckDB 2.0 feature and is documented as the recommended shorthand for getvariable().
  • Users who write SQL against DuckDB 2.0+ cannot format their queries through this tool if they use the $variable syntax.
  • The getvariable('name') workaround is functionally equivalent but more verbose; users should be able to use the idiomatic syntax and still benefit from formatting.
  • The parser already supports $1-style positional parameters; extending this to named variables in the DuckDB dialect is a natural addition.

Activity

  1. added and removed on Nov 20, 2026
  2. nene commented on Nov 20, 2026

    @nene
    Collaborator

    This is a known issue, but thanks for reporting.

    The problem is, that this $variable syntax kinda conflicts with dollar-quoted strings $tag$string$tag$ syntax.

    But I think I have a fix for this. I'll prioritize the tokenization of strings before these variables.

  3. nene commented on Nov 20, 2026

    @nene
    Collaborator

    This should now be fixed in 15.10.0

  4. gltjk commented on Nov 20, 2026

    @gltjk
    Author

    This should now be fixed in 15.10.0

    Thanks for the quick fix! 🎉 Tested with 15.10.0 and it works perfectly.

  5. added a commit that references this issue on Nov 20, 2026
    cd8a82e
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions