Skip to content

Commit caaaad4

Browse files
kyleconroyclaude
andcommitted
Handle double-paren grouping sets as Function tuple (#123)
When GROUPING SETS contains ((a,b,c)) with double parentheses, the inner tuple should be output as Function tuple, not unwrapped. Use the Parenthesized flag on tuple literals to detect double-paren cases. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5deac6f commit caaaad4

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

internal/explain/select.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,22 @@ func explainSelectQuery(sb *strings.Builder, n *ast.SelectQuery, indent string,
401401
// Each grouping set is wrapped in an ExpressionList
402402
// but we need to unwrap tuples and output elements directly
403403
if lit, ok := g.(*ast.Literal); ok && lit.Type == ast.LiteralTuple {
404-
if elements, ok := lit.Value.([]ast.Expression); ok {
404+
// Check if this tuple was from double parens ((a,b,c)) - marked as Parenthesized
405+
// In that case, output as Function tuple wrapped in ExpressionList(1)
406+
if lit.Parenthesized {
407+
if elements, ok := lit.Value.([]ast.Expression); ok {
408+
fmt.Fprintf(sb, "%s ExpressionList (children 1)\n", indent)
409+
fmt.Fprintf(sb, "%s Function tuple (children 1)\n", indent)
410+
if len(elements) > 0 {
411+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(elements))
412+
for _, elem := range elements {
413+
Node(sb, elem, depth+5)
414+
}
415+
} else {
416+
fmt.Fprintf(sb, "%s ExpressionList\n", indent)
417+
}
418+
}
419+
} else if elements, ok := lit.Value.([]ast.Expression); ok {
405420
if len(elements) == 0 {
406421
// Empty grouping set () outputs ExpressionList without children count
407422
fmt.Fprintf(sb, "%s ExpressionList\n", indent)
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)