Skip to content

Commit 5267c09

Browse files
author
James Cor
committed
checkout group by ordinal range
1 parent 45c4c4c commit 5267c09

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

enginetest/queries/script_queries.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7782,6 +7782,32 @@ where
77827782
},
77837783
},
77847784
},
7785+
{
7786+
Name: "group by ordinal tests",
7787+
Dialect: "mysql",
7788+
SetUpScript: []string{
7789+
"create table t (i int, j int);",
7790+
},
7791+
Assertions: []ScriptTestAssertion{
7792+
{
7793+
Query: "select 1 from t group by 'abc';",
7794+
ExpectedErrStr: "expected integer order by literal",
7795+
},
7796+
{
7797+
// TODO: this actually works in MySQL
7798+
Query: "select 1 from t group by -123;",
7799+
ExpectedErrStr: "expected positive integer order by literal",
7800+
},
7801+
{
7802+
Query: "select 1 from t group by 0;",
7803+
ExpectedErrStr: "expected positive integer order by literal",
7804+
},
7805+
{
7806+
Query: "select 1 from t group by 100;",
7807+
ExpectedErrStr: "column ordinal out of range: 100",
7808+
},
7809+
},
7810+
},
77857811
}
77867812

77877813
var SpatialScriptTests = []ScriptTest{

sql/planbuilder/aggregates.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ func (b *Builder) buildGroupingCols(fromScope, projScope *scope, groupby ast.Gro
131131
b.handleErr(fmt.Errorf("expected integer order by literal"))
132132
}
133133
if intIdx < 1 {
134+
// TODO: this actually works in MySQL
134135
b.handleErr(fmt.Errorf("expected positive integer order by literal"))
135136
}
137+
if int(intIdx) > len(selects) {
138+
b.handleErr(fmt.Errorf("column ordinal out of range: %d", intIdx))
139+
}
136140
col = projScope.cols[intIdx-1]
137141
default:
138142
expr := b.buildScalar(fromScope, e)

0 commit comments

Comments
 (0)