From 28ef9f18811d432e4b63cd4b19d7be90fc649ee8 Mon Sep 17 00:00:00 2001 From: hulk <4987594+git-hulk@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:08:54 +0000 Subject: [PATCH 1/3] Parse ClickHouse heredocs as string literals 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 #346 Assistant-By gpt-6.2-astra --- parser/lexer.go | 39 ++++- .../query/format/beautify/select_heredoc.sql | 15 ++ .../testdata/query/format/select_heredoc.sql | 10 ++ .../output/select_heredoc.sql.golden.json | 145 ++++++++++++++++++ parser/testdata/query/select_heredoc.sql | 3 + 5 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 parser/testdata/query/format/beautify/select_heredoc.sql create mode 100644 parser/testdata/query/format/select_heredoc.sql create mode 100644 parser/testdata/query/output/select_heredoc.sql.golden.json create mode 100644 parser/testdata/query/select_heredoc.sql diff --git a/parser/lexer.go b/parser/lexer.go index ac54dd6a..eb7c941e 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -271,6 +271,38 @@ func (l *Lexer) consumeMultiLineComment() error { return &lexerError{pos: pos, err: errors.New("unclosed multi-line comment")} } +// String tokens store the escaped contents of a single-quoted SQL literal. +// Heredoc bodies are raw, so escape them once when creating the token. +var heredocEscaper = strings.NewReplacer("\\", "\\\\", "'", "''") + +func (l *Lexer) tryConsumeHeredoc() bool { + i := 1 + for l.peekOk(i) && (IsIdentStart(l.peekN(i)) || IsDigit(l.peekN(i))) { + i++ + } + if !l.peekOk(i) || l.peekN(i) != '$' { + return false + } + + delimiter := l.slice(0, i+1) + bodyStart := l.offset + len(delimiter) + bodyLength := strings.Index(l.input[bodyStart:], delimiter) + if bodyLength < 0 { + return false + } + + bodyEnd := bodyStart + bodyLength + end := bodyEnd + len(delimiter) + l.currentToken = &Token{ + Kind: TokenKindString, + String: heredocEscaper.Replace(l.input[bodyStart:bodyEnd]), + Pos: Pos(l.offset), + End: Pos(end), + } + l.offset = end + return true +} + func (l *Lexer) consumeString() error { i := 1 endChar := byte('\'') @@ -417,7 +449,12 @@ func (l *Lexer) consumeToken() (err error) { } case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': return l.consumeNumber() - case '`', '$', '"': + case '$': + if l.tryConsumeHeredoc() { + return nil + } + fallthrough + case '`', '"': return l.consumeIdent(Pos(l.offset)) case '\'': return l.consumeString() diff --git a/parser/testdata/query/format/beautify/select_heredoc.sql b/parser/testdata/query/format/beautify/select_heredoc.sql new file mode 100644 index 00000000..4c24b9f6 --- /dev/null +++ b/parser/testdata/query/format/beautify/select_heredoc.sql @@ -0,0 +1,15 @@ +-- Origin SQL: +SELECT $tag$hello$tag$; +SELECT $x$ AS a FROM t WHERE b = $x$; +SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; + + +-- Beautify SQL: +SELECT + 'hello'; +SELECT + ' AS a FROM t WHERE b = '; +SELECT + 'it''s\\raw' AS service$$name, + 1 AS a$b, + 2 AS $open$; diff --git a/parser/testdata/query/format/select_heredoc.sql b/parser/testdata/query/format/select_heredoc.sql new file mode 100644 index 00000000..829670d4 --- /dev/null +++ b/parser/testdata/query/format/select_heredoc.sql @@ -0,0 +1,10 @@ +-- Origin SQL: +SELECT $tag$hello$tag$; +SELECT $x$ AS a FROM t WHERE b = $x$; +SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; + + +-- Format SQL: +SELECT 'hello'; +SELECT ' AS a FROM t WHERE b = '; +SELECT 'it''s\\raw' AS service$$name, 1 AS a$b, 2 AS $open$; diff --git a/parser/testdata/query/output/select_heredoc.sql.golden.json b/parser/testdata/query/output/select_heredoc.sql.golden.json new file mode 100644 index 00000000..09878f5e --- /dev/null +++ b/parser/testdata/query/output/select_heredoc.sql.golden.json @@ -0,0 +1,145 @@ +[ + { + "SelectPos": 0, + "StatementEnd": 22, + "With": null, + "Top": null, + "HasDistinct": false, + "DistinctOn": null, + "SelectItems": [ + { + "Expr": { + "LiteralPos": 7, + "LiteralEnd": 22, + "Literal": "hello" + }, + "Modifiers": [], + "Alias": null + } + ], + "From": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "Qualify": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null, + "Intersect": null + }, + { + "SelectPos": 24, + "StatementEnd": 60, + "With": null, + "Top": null, + "HasDistinct": false, + "DistinctOn": null, + "SelectItems": [ + { + "Expr": { + "LiteralPos": 31, + "LiteralEnd": 60, + "Literal": " AS a FROM t WHERE b = " + }, + "Modifiers": [], + "Alias": null + } + ], + "From": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "Qualify": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null, + "Intersect": null + }, + { + "SelectPos": 62, + "StatementEnd": 121, + "With": null, + "Top": null, + "HasDistinct": false, + "DistinctOn": null, + "SelectItems": [ + { + "Expr": { + "LiteralPos": 69, + "LiteralEnd": 81, + "Literal": "it''s\\\\raw" + }, + "Modifiers": [], + "Alias": { + "Name": "service$$name", + "QuoteType": 1, + "NamePos": 85, + "NameEnd": 98 + } + }, + { + "Expr": { + "NumPos": 100, + "NumEnd": 101, + "Literal": "1", + "Base": 10 + }, + "Modifiers": [], + "Alias": { + "Name": "a$b", + "QuoteType": 1, + "NamePos": 105, + "NameEnd": 108 + } + }, + { + "Expr": { + "NumPos": 110, + "NumEnd": 111, + "Literal": "2", + "Base": 10 + }, + "Modifiers": [], + "Alias": { + "Name": "$open$", + "QuoteType": 1, + "NamePos": 115, + "NameEnd": 121 + } + } + ], + "From": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "Qualify": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null, + "Intersect": null + } +] \ No newline at end of file diff --git a/parser/testdata/query/select_heredoc.sql b/parser/testdata/query/select_heredoc.sql new file mode 100644 index 00000000..ae56ade5 --- /dev/null +++ b/parser/testdata/query/select_heredoc.sql @@ -0,0 +1,3 @@ +SELECT $tag$hello$tag$; +SELECT $x$ AS a FROM t WHERE b = $x$; +SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; From 04106c019a1fd5445f7eb3da0014e145a24358ce Mon Sep 17 00:00:00 2001 From: hulk <4987594+git-hulk@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:11:57 +0000 Subject: [PATCH 2/3] Document heredoc parsing with a SQL example --- parser/lexer.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parser/lexer.go b/parser/lexer.go index eb7c941e..555da470 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -275,6 +275,8 @@ func (l *Lexer) consumeMultiLineComment() error { // Heredoc bodies are raw, so escape them once when creating the token. var heredocEscaper = strings.NewReplacer("\\", "\\\\", "'", "''") +// tryConsumeHeredoc reads a string between matching dollar-quoted delimiters. +// For example, SELECT $tag$FROM t$tag$ returns the string 'FROM t'. func (l *Lexer) tryConsumeHeredoc() bool { i := 1 for l.peekOk(i) && (IsIdentStart(l.peekN(i)) || IsDigit(l.peekN(i))) { From 8b9f90c21cdca3163eab44332d38957efa755d45 Mon Sep 17 00:00:00 2001 From: hulk <4987594+git-hulk@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:29:11 +0000 Subject: [PATCH 3/3] Preserve heredoc delimiters when formatting SQL 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. --- parser/ast_literal.go | 16 +++--- parser/format.go | 13 +++++ parser/lexer.go | 33 +++++++------ parser/parser_common.go | 16 +++--- parser/parser_row_policy.go | 2 +- .../ddl/format/beautify/row_policy.sql | 2 + parser/testdata/ddl/format/row_policy.sql | 2 + .../ddl/output/row_policy.sql.golden.json | 49 +++++++++++++++++++ parser/testdata/ddl/row_policy.sql | 1 + .../query/format/beautify/select_heredoc.sql | 11 +++-- .../testdata/query/format/select_heredoc.sql | 10 ++-- .../output/select_heredoc.sql.golden.json | 46 +++++++++++++++-- parser/testdata/query/select_heredoc.sql | 2 + 13 files changed, 163 insertions(+), 40 deletions(-) diff --git a/parser/ast_literal.go b/parser/ast_literal.go index 118c3db8..b87bf1ca 100644 --- a/parser/ast_literal.go +++ b/parser/ast_literal.go @@ -1,10 +1,11 @@ package parser type Ident struct { - Name string - QuoteType int - NamePos Pos - NameEnd Pos + Name string + QuoteType int + NamePos Pos + NameEnd Pos + HeredocDelimiter string `json:",omitempty"` } func (i *Ident) Pos() Pos { @@ -286,9 +287,10 @@ func (n *NumberLiteral) Accept(visitor ASTVisitor) error { } type StringLiteral struct { - LiteralPos Pos - LiteralEnd Pos - Literal string + LiteralPos Pos + LiteralEnd Pos + Literal string + HeredocDelimiter string `json:",omitempty"` } func (s *StringLiteral) Pos() Pos { diff --git a/parser/format.go b/parser/format.go index 231efcec..715dbaa0 100644 --- a/parser/format.go +++ b/parser/format.go @@ -1666,6 +1666,8 @@ func (i *Ident) FormatSQL(formatter *Formatter) { formatter.WriteByte('"') formatter.WriteString(i.Name) formatter.WriteByte('"') + case HeredocQuote: + formatter.writeHeredoc(i.HeredocDelimiter, i.Name) case SingleQuote: formatter.WriteByte('\'') formatter.WriteString(i.Name) @@ -2513,7 +2515,18 @@ func (s *ShowStmt) FormatSQL(formatter *Formatter) { } +func (f *Formatter) writeHeredoc(delimiter, body string) { + f.WriteString(delimiter) + // Indentation inside the body would change the string value. + f.builder.WriteString(body) + f.WriteString(delimiter) +} + func (s *StringLiteral) FormatSQL(formatter *Formatter) { + if s.HeredocDelimiter != "" { + formatter.writeHeredoc(s.HeredocDelimiter, s.Literal) + return + } formatter.WriteByte('\'') formatter.WriteString(s.Literal) formatter.WriteByte('\'') diff --git a/parser/lexer.go b/parser/lexer.go index 555da470..b049164c 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -52,6 +52,7 @@ const ( DoubleQuote BackTicks SingleQuote + HeredocQuote ) type Pos int @@ -61,10 +62,11 @@ type Token struct { Pos Pos End Pos - Kind TokenKind - String string - Base int // 10 or 16 on TokenKindInt - QuoteType int + Kind TokenKind + String string + Base int // 10 or 16 on TokenKindInt + QuoteType int + heredocDelimiter string } func (t *Token) ToString() string { @@ -271,10 +273,6 @@ func (l *Lexer) consumeMultiLineComment() error { return &lexerError{pos: pos, err: errors.New("unclosed multi-line comment")} } -// String tokens store the escaped contents of a single-quoted SQL literal. -// Heredoc bodies are raw, so escape them once when creating the token. -var heredocEscaper = strings.NewReplacer("\\", "\\\\", "'", "''") - // tryConsumeHeredoc reads a string between matching dollar-quoted delimiters. // For example, SELECT $tag$FROM t$tag$ returns the string 'FROM t'. func (l *Lexer) tryConsumeHeredoc() bool { @@ -296,10 +294,12 @@ func (l *Lexer) tryConsumeHeredoc() bool { bodyEnd := bodyStart + bodyLength end := bodyEnd + len(delimiter) l.currentToken = &Token{ - Kind: TokenKindString, - String: heredocEscaper.Replace(l.input[bodyStart:bodyEnd]), - Pos: Pos(l.offset), - End: Pos(end), + Kind: TokenKindString, + String: l.input[bodyStart:bodyEnd], + QuoteType: HeredocQuote, + heredocDelimiter: delimiter, + Pos: Pos(l.offset), + End: Pos(end), } l.offset = end return true @@ -333,10 +333,11 @@ func (l *Lexer) consumeString() error { return errors.New("invalid string") } l.currentToken = &Token{ - Kind: TokenKindString, - String: l.slice(1, i), - Pos: Pos(l.offset), - End: Pos(l.offset + i + 1), + Kind: TokenKindString, + QuoteType: SingleQuote, + String: l.slice(1, i), + Pos: Pos(l.offset), + End: Pos(l.offset + i + 1), } l.skipN(i + 1) return nil diff --git a/parser/parser_common.go b/parser/parser_common.go index 1b72da17..a870fa9c 100644 --- a/parser/parser_common.go +++ b/parser/parser_common.go @@ -238,10 +238,11 @@ func (p *Parser) parseIdentOrString() (*Ident, error) { curToken := p.current() _ = p.lexer.consumeToken() return &Ident{ - NamePos: curToken.Pos, - NameEnd: curToken.End, - Name: curToken.String, - QuoteType: SingleQuote, // Treat string literals as single-quoted identifiers + NamePos: curToken.Pos, + NameEnd: curToken.End, + Name: curToken.String, + QuoteType: curToken.QuoteType, + HeredocDelimiter: curToken.heredocDelimiter, }, nil default: return nil, fmt.Errorf("expected or , but got %q", p.currentTokenKind()) @@ -401,9 +402,10 @@ func (p *Parser) parseString(pos Pos) (*StringLiteral, error) { } str := &StringLiteral{ - LiteralPos: pos, - LiteralEnd: curToken.End, - Literal: curToken.String, + LiteralPos: pos, + LiteralEnd: curToken.End, + Literal: curToken.String, + HeredocDelimiter: curToken.heredocDelimiter, } return str, nil } diff --git a/parser/parser_row_policy.go b/parser/parser_row_policy.go index e3be4223..7d45d40e 100644 --- a/parser/parser_row_policy.go +++ b/parser/parser_row_policy.go @@ -300,7 +300,7 @@ func (p *Parser) parseRowPolicyPrincipal() (*RowPolicyPrincipal, error) { return nil, err } principal.PrincipalEnd = rowPolicyIdentEnd(principal.Name) - if principal.Name.QuoteType != SingleQuote && p.matchTokenKind(TokenKindAtSign) { + if principal.Name.QuoteType != SingleQuote && principal.Name.QuoteType != HeredocQuote && p.matchTokenKind(TokenKindAtSign) { if _, err := p.tryConsumeTokenKind(TokenKindAtSign); err != nil { return nil, err } diff --git a/parser/testdata/ddl/format/beautify/row_policy.sql b/parser/testdata/ddl/format/beautify/row_policy.sql index b53c2e25..794b6171 100644 --- a/parser/testdata/ddl/format/beautify/row_policy.sql +++ b/parser/testdata/ddl/format/beautify/row_policy.sql @@ -11,6 +11,7 @@ SHOW CREATE ROW POLICIES ON db.*; SHOW ROW POLICIES; CREATE ROW POLICY selected_rows ON db.example_table FOR SELECT USING id > 0 TO example_role; CREATE ROW POLICY all_commands ON db.example_table FOR ALL USING id > 0 TO example_role; +CREATE ROW POLICY $p$example$p$ ON t USING 1; -- Beautify SQL: @@ -26,3 +27,4 @@ SHOW CREATE ROW POLICIES ON db.*; SHOW ROW POLICIES; CREATE ROW POLICY selected_rows ON db.example_table FOR SELECT USING id > 0 TO example_role; CREATE ROW POLICY all_commands ON db.example_table FOR ALL USING id > 0 TO example_role; +CREATE ROW POLICY $p$example$p$ ON t USING 1; diff --git a/parser/testdata/ddl/format/row_policy.sql b/parser/testdata/ddl/format/row_policy.sql index 3f341c4b..d0e9f154 100644 --- a/parser/testdata/ddl/format/row_policy.sql +++ b/parser/testdata/ddl/format/row_policy.sql @@ -11,6 +11,7 @@ SHOW CREATE ROW POLICIES ON db.*; SHOW ROW POLICIES; CREATE ROW POLICY selected_rows ON db.example_table FOR SELECT USING id > 0 TO example_role; CREATE ROW POLICY all_commands ON db.example_table FOR ALL USING id > 0 TO example_role; +CREATE ROW POLICY $p$example$p$ ON t USING 1; -- Format SQL: @@ -26,3 +27,4 @@ SHOW CREATE ROW POLICIES ON db.*; SHOW ROW POLICIES; CREATE ROW POLICY selected_rows ON db.example_table FOR SELECT USING id > 0 TO example_role; CREATE ROW POLICY all_commands ON db.example_table FOR ALL USING id > 0 TO example_role; +CREATE ROW POLICY $p$example$p$ ON t USING 1; diff --git a/parser/testdata/ddl/output/row_policy.sql.golden.json b/parser/testdata/ddl/output/row_policy.sql.golden.json index 68261b4c..4c1bb04b 100644 --- a/parser/testdata/ddl/output/row_policy.sql.golden.json +++ b/parser/testdata/ddl/output/row_policy.sql.golden.json @@ -990,5 +990,54 @@ ], "Except": null } + }, + { + "CreatePos": 1159, + "StatementEnd": 1203, + "IfNotExists": false, + "OrReplace": false, + "Targets": [ + { + "PolicyName": { + "Name": "example", + "QuoteType": 5, + "NamePos": 1177, + "NameEnd": 1190, + "HeredocDelimiter": "$p$" + }, + "Table": { + "Database": null, + "Table": { + "Name": "t", + "QuoteType": 1, + "NamePos": 1194, + "NameEnd": 1195 + } + } + } + ], + "OnCluster": null, + "AccessStorageType": null, + "Mode": "", + "Filters": [ + { + "FilterPos": 1196, + "FilterEnd": 1203, + "Commands": null, + "Using": { + "ConditionPos": 1202, + "ConditionEnd": 1203, + "None": false, + "Expr": { + "NumPos": 1202, + "NumEnd": 1203, + "Literal": "1", + "Base": 10 + } + }, + "WithCheck": null + } + ], + "To": null } ] \ No newline at end of file diff --git a/parser/testdata/ddl/row_policy.sql b/parser/testdata/ddl/row_policy.sql index 6862716c..648c86a9 100644 --- a/parser/testdata/ddl/row_policy.sql +++ b/parser/testdata/ddl/row_policy.sql @@ -10,3 +10,4 @@ SHOW CREATE ROW POLICIES ON db.*; SHOW ROW POLICIES; CREATE ROW POLICY selected_rows ON db.example_table FOR SELECT USING id > 0 TO example_role; CREATE ROW POLICY all_commands ON db.example_table FOR ALL USING id > 0 TO example_role; +CREATE ROW POLICY $p$example$p$ ON t USING 1; diff --git a/parser/testdata/query/format/beautify/select_heredoc.sql b/parser/testdata/query/format/beautify/select_heredoc.sql index 4c24b9f6..c38f9b98 100644 --- a/parser/testdata/query/format/beautify/select_heredoc.sql +++ b/parser/testdata/query/format/beautify/select_heredoc.sql @@ -2,14 +2,19 @@ SELECT $tag$hello$tag$; SELECT $x$ AS a FROM t WHERE b = $x$; SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; +SELECT $t_1$it's\raw +and $$ inside$t_1$; -- Beautify SQL: SELECT - 'hello'; + $tag$hello$tag$; SELECT - ' AS a FROM t WHERE b = '; + $x$ AS a FROM t WHERE b = $x$; SELECT - 'it''s\\raw' AS service$$name, + $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; +SELECT + $t_1$it's\raw +and $$ inside$t_1$; diff --git a/parser/testdata/query/format/select_heredoc.sql b/parser/testdata/query/format/select_heredoc.sql index 829670d4..3fdb0fdf 100644 --- a/parser/testdata/query/format/select_heredoc.sql +++ b/parser/testdata/query/format/select_heredoc.sql @@ -2,9 +2,13 @@ SELECT $tag$hello$tag$; SELECT $x$ AS a FROM t WHERE b = $x$; SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; +SELECT $t_1$it's\raw +and $$ inside$t_1$; -- Format SQL: -SELECT 'hello'; -SELECT ' AS a FROM t WHERE b = '; -SELECT 'it''s\\raw' AS service$$name, 1 AS a$b, 2 AS $open$; +SELECT $tag$hello$tag$; +SELECT $x$ AS a FROM t WHERE b = $x$; +SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; +SELECT $t_1$it's\raw +and $$ inside$t_1$; diff --git a/parser/testdata/query/output/select_heredoc.sql.golden.json b/parser/testdata/query/output/select_heredoc.sql.golden.json index 09878f5e..73f90a71 100644 --- a/parser/testdata/query/output/select_heredoc.sql.golden.json +++ b/parser/testdata/query/output/select_heredoc.sql.golden.json @@ -11,7 +11,8 @@ "Expr": { "LiteralPos": 7, "LiteralEnd": 22, - "Literal": "hello" + "Literal": "hello", + "HeredocDelimiter": "$tag$" }, "Modifiers": [], "Alias": null @@ -47,7 +48,8 @@ "Expr": { "LiteralPos": 31, "LiteralEnd": 60, - "Literal": " AS a FROM t WHERE b = " + "Literal": " AS a FROM t WHERE b = ", + "HeredocDelimiter": "$x$" }, "Modifiers": [], "Alias": null @@ -83,7 +85,8 @@ "Expr": { "LiteralPos": 69, "LiteralEnd": 81, - "Literal": "it''s\\\\raw" + "Literal": "it's\\raw", + "HeredocDelimiter": "$$" }, "Modifiers": [], "Alias": { @@ -141,5 +144,42 @@ "UnionDistinct": null, "Except": null, "Intersect": null + }, + { + "SelectPos": 123, + "StatementEnd": 162, + "With": null, + "Top": null, + "HasDistinct": false, + "DistinctOn": null, + "SelectItems": [ + { + "Expr": { + "LiteralPos": 130, + "LiteralEnd": 162, + "Literal": "it's\\raw\nand $$ inside", + "HeredocDelimiter": "$t_1$" + }, + "Modifiers": [], + "Alias": null + } + ], + "From": null, + "Window": null, + "Prewhere": null, + "Where": null, + "GroupBy": null, + "WithTotal": false, + "Having": null, + "Qualify": null, + "OrderBy": null, + "LimitBy": null, + "Limit": null, + "Settings": null, + "Format": null, + "UnionAll": null, + "UnionDistinct": null, + "Except": null, + "Intersect": null } ] \ No newline at end of file diff --git a/parser/testdata/query/select_heredoc.sql b/parser/testdata/query/select_heredoc.sql index ae56ade5..699cd6c4 100644 --- a/parser/testdata/query/select_heredoc.sql +++ b/parser/testdata/query/select_heredoc.sql @@ -1,3 +1,5 @@ SELECT $tag$hello$tag$; SELECT $x$ AS a FROM t WHERE b = $x$; SELECT $$it's\raw$$ AS service$$name, 1 AS a$b, 2 AS $open$; +SELECT $t_1$it's\raw +and $$ inside$t_1$;