Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/semantic/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions compiler/ztests/sql/group-by-ordinal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down
Loading