Skip to content

Commit 21156b7

Browse files
kyleconroyclaude
andcommitted
Fix nested parenthesized query expression parsing
Handle cases where derived tables contain nested query expressions with UNION/EXCEPT/INTERSECT, such as: SELECT * FROM ((SELECT ...) UNION ALL SELECT ...) AS C; Enables: BaselinesCommon_QueryExpressionTests, QueryExpressionTests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9da649c commit 21156b7

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

parser/parse_select.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,8 +2545,9 @@ func (p *Parser) parseDerivedTableReference() (ast.TableReference, error) {
25452545
return p.parseDataModificationTableReference("MERGE")
25462546
}
25472547

2548-
// Check if this is a query (starts with SELECT, WITH) or a parenthesized table reference
2549-
if p.curTok.Type != TokenSelect && p.curTok.Type != TokenWith {
2548+
// Check if this is a query (starts with SELECT, WITH, or another parenthesis for nested query)
2549+
// or a parenthesized table reference (e.g., (t1 JOIN t2 ON ...))
2550+
if p.curTok.Type != TokenSelect && p.curTok.Type != TokenWith && p.curTok.Type != TokenLParen {
25502551
// This is a parenthesized table reference (e.g., (t1 JOIN t2 ON ...))
25512552
tableRef, err := p.parseTableReference()
25522553
if err != nil {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)