Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlparser): fix order by followed by scalar #16967

Merged
merged 2 commits into from
Dec 2, 2024
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
4 changes: 4 additions & 0 deletions src/query/sql/src/planner/binder/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Binder {
)
.map_err(|e| ErrorCode::SemanticError(e.message()))?;

if let ScalarExpr::ConstantExpr(..) = rewrite_scalar {
continue;
}

let column_binding =
if let ScalarExpr::BoundColumnRef(col) = &rewrite_scalar {
col.column.clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,60 @@ SELECT number FROM numbers_mt(10) ORDER BY sum(number)

statement error 1065
SELECT number FROM numbers_mt(10) ORDER BY count(*) + 1

statement ok
CREATE TABLE t1(a int, b int);

statement ok
INSERT INTO t1 VALUES(1, 3),(2, 1), (3, 2)

query I
SELECT * from t1 order by 1;
----
1 3
2 1
3 2

query I
SELECT * from t1 order by 2;
----
2 1
3 2
1 3

statement error 1065
SELECT * from t1 order by 3;

query I
SELECT * from t1 order by t1.a;
----
1 3
2 1
3 2

query I
SELECT * from t1 order by t1.b;
----
2 1
3 2
1 3

statement error 1065
SELECT * from t1 order by t1.1;

query I
SELECT * from t1 order by 'a';
----
1 3
2 1
3 2

query I
SELECT * from t1 order by '1', 1;
----
1 3
2 1
3 2

statement ok
DROP TABLE if EXISTS t1