Skip to content

Parse ClickHouse heredocs as string literals - #347

Merged
git-hulk merged 3 commits into
AfterShip:masterfrom
git-hulk:fix/heredoc-string-literals
Nov 20, 2026
Merged

git-hulk merged 3 commits into
AfterShip:masterfrom
git-hulk:fix/heredoc-string-literals

Conversation

@git-hulk

@git-hulk git-hulk commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

The lexer treated a leading $ as the start of an identifier, so the
AST could describe clauses that ClickHouse reads as string content.

For SELECT $x$ AS a FROM t WHERE b = $x$, the parser reported a table
and a filter. ClickHouse returns a single string containing the text
between the two $x$ delimiters.

Recognize matching heredoc delimiters using the ClickHouse 26.x tag
rules. Keep the original delimiter and raw body in the AST so both
compact and beautified SQL preserve the heredoc spelling, including
whitespace inside multiline strings. Identifiers such as service$$name
and a$b still parse as before.

Fixes #346

Assistant-By gpt-6.2-astra

The lexer treated a leading `$` as the start of an identifier, so the
AST could describe clauses that ClickHouse reads as string content.

For `SELECT $x$ AS a FROM t WHERE b = $x$`, the parser reported a table
and a filter. ClickHouse returns the single string `' AS a FROM t WHERE b = '`.

Recognize matching heredoc delimiters using the ClickHouse 26.x tag
rules. Format the body as a single-quoted literal, escaping quotes and
backslashes to preserve its value. Identifiers such as `service$$name`
and `a$b` still parse as before. The new AST and formatting fixtures
cover both reported queries.

Fixes AfterShip#346

Assistant-By gpt-6.2-astra
Keep the original delimiter and raw body in the AST so both compact
and beautified SQL retain the heredoc spelling. Write multiline bodies
verbatim because indentation becomes part of the string value.
@git-hulk
git-hulk merged commit d4b5931 into AfterShip:master Nov 20, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant