From 4b51c52118fa02b8bf8f63f65db5b7c59c0f4cce Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Thu, 17 Sep 2026 15:32:12 -0700 Subject: [PATCH] Fix panic on group by ordinal work with select * Fixes #7296 --- compiler/semantic/sql.go | 8 +++++++- compiler/ztests/sql/group-by-ordinal.yaml | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler/semantic/sql.go b/compiler/semantic/sql.go index 88bac80675..8c60dda330 100644 --- a/compiler/semantic/sql.go +++ b/compiler/semantic/sql.go @@ -674,7 +674,13 @@ func (t *translator) groupBy(sch *selectScope, in []ast.Expr, inType super.Type) } else { save := sch.groupByLoc sch.groupByLoc = expr - e, typ = t.expr(sch.columns[colno-1].astExpr, inType) + if col := sch.columns[colno-1]; col.semExpr != nil { + // If semExpr is not nil, column refers to an expanded star + // expression - use this value. + e, typ = col.semExpr, col.typ + } else { + e, typ = t.expr(col.astExpr, inType) + } sch.groupByLoc = save } } else { diff --git a/compiler/ztests/sql/group-by-ordinal.yaml b/compiler/ztests/sql/group-by-ordinal.yaml index 242db162ae..19dd601b3f 100644 --- a/compiler/ztests/sql/group-by-ordinal.yaml +++ b/compiler/ztests/sql/group-by-ordinal.yaml @@ -2,6 +2,8 @@ script: | super -s -c 'select a from test.sup group by 1,1' echo // === super -s -c 'select 1, b, count() as c from test.sup group by 1, b order by c desc' + echo // === + super -s -c 'select * from test.sup group by 1,2,3,4' ! super -s -c 'select a, b, c, d from test.sup group by 5, 0' echo // === >&2 ! super -s -c 'select count() as c, a from test.sup group by 1,2' @@ -20,6 +22,9 @@ outputs: // === {"1":1,b:"foo",c:2} {"1":1,b:"bar",c:1} + // === + {a:1,b:"foo",c:1,d:1} + {a:1,b:"bar",c:1,d:1} - name: stderr data: | position 5 is not in select list at line 1, column 42: