Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 26 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -7782,6 +7782,32 @@ where
},
},
},
{
Name: "group by ordinal tests",
Dialect: "mysql",
SetUpScript: []string{
"create table t (i int, j int);",
},
Assertions: []ScriptTestAssertion{
{
Query: "select 1 from t group by 'abc';",
ExpectedErrStr: "expected integer order by literal",
},
{
// TODO: this actually works in MySQL
Query: "select 1 from t group by -123;",
ExpectedErrStr: "expected positive integer order by literal",
},
{
Query: "select 1 from t group by 0;",
ExpectedErrStr: "expected positive integer order by literal",
},
{
Query: "select 1 from t group by 100;",
ExpectedErrStr: "column ordinal out of range: 100",
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
4 changes: 4 additions & 0 deletions sql/planbuilder/aggregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ func (b *Builder) buildGroupingCols(fromScope, projScope *scope, groupby ast.Gro
b.handleErr(fmt.Errorf("expected integer order by literal"))
}
if intIdx < 1 {
// TODO: this actually works in MySQL
b.handleErr(fmt.Errorf("expected positive integer order by literal"))
}
if int(intIdx) > len(selects) {
b.handleErr(fmt.Errorf("column ordinal out of range: %d", intIdx))
}
col = projScope.cols[intIdx-1]
default:
expr := b.buildScalar(fromScope, e)
Expand Down
Loading