Skip to content

Heredoc string literals ($tag$ … $tag$) are lexed as identifiers #346

Closed

Description

@thiemok

ClickHouse reads $tag$…$tag$ as a heredoc string literal. The parser lexes these tokens as unquoted identifiers, and Format re-emits them bare. As a result, the AST and the formatted SQL disagree with what ClickHouse executes: ClickHouse reads everything between two $x$ tokens as one string.
The cause is #147 (the fix for #144, service$$name), which added $ to IsIdentPart. Since then an unquoted identifier runs on through every $.

Reproduction (v0.5.7)

stmts, _ := parser.NewParser("SELECT $x$ AS a FROM t WHERE b = $x$").ParseStmts()
fmt.Println(parser.Format(stmts[0]))
// SELECT $x$ AS a FROM t WHERE b = $x$  (both $x$ tokens are *parser.Ident)
Query Parser ClickHouse 24.6 / 25.6 / 26.6
SELECT $tag$hello$tag$ identifier $tag$hello$tag$ string 'hello'
SELECT $x$ AS a FROM t WHERE b = $x$ identifiers $x$, a, t, b, $x$ string ' AS a FROM t WHERE b = '
On 26.x the tag must match [A-Za-z0-9_]*. Before 26.x it can contain any characters up to the next $.

Expected behaviour

Lex $tag$…$tag$ as a string literal and format it so it round-trips. A $ inside or at the end of a bare word (service$$name, a$b) should stay valid, as #144 requires.

Activity

  1. git-hulk commented on Nov 20, 2026

    @git-hulk
    Member

    @thiemok Thanks for your report, it has been resolved in #347.

  2. added theissue type on Nov 20, 2026
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions