Skip to content

Commit 35c1c24

Browse files
authored
fix(sqlparser): fix order by followed by scalar (#16967)
* fix(sqlparser): fix order by followed by scalar Signed-off-by: chagelo <[email protected]> * fix Signed-off-by: chagelo <[email protected]> --------- Signed-off-by: chagelo <[email protected]>
1 parent c496fce commit 35c1c24

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/query/sql/src/planner/binder/sort.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ impl Binder {
148148
)
149149
.map_err(|e| ErrorCode::SemanticError(e.message()))?;
150150

151+
if let ScalarExpr::ConstantExpr(..) = rewrite_scalar {
152+
continue;
153+
}
154+
151155
let column_binding =
152156
if let ScalarExpr::BoundColumnRef(col) = &rewrite_scalar {
153157
col.column.clone()

tests/sqllogictests/suites/base/03_common/03_0004_select_order_by.test

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,60 @@ SELECT number FROM numbers_mt(10) ORDER BY sum(number)
132132

133133
statement error 1065
134134
SELECT number FROM numbers_mt(10) ORDER BY count(*) + 1
135+
136+
statement ok
137+
CREATE TABLE t1(a int, b int);
138+
139+
statement ok
140+
INSERT INTO t1 VALUES(1, 3),(2, 1), (3, 2)
141+
142+
query I
143+
SELECT * from t1 order by 1;
144+
----
145+
1 3
146+
2 1
147+
3 2
148+
149+
query I
150+
SELECT * from t1 order by 2;
151+
----
152+
2 1
153+
3 2
154+
1 3
155+
156+
statement error 1065
157+
SELECT * from t1 order by 3;
158+
159+
query I
160+
SELECT * from t1 order by t1.a;
161+
----
162+
1 3
163+
2 1
164+
3 2
165+
166+
query I
167+
SELECT * from t1 order by t1.b;
168+
----
169+
2 1
170+
3 2
171+
1 3
172+
173+
statement error 1065
174+
SELECT * from t1 order by t1.1;
175+
176+
query I
177+
SELECT * from t1 order by 'a';
178+
----
179+
1 3
180+
2 1
181+
3 2
182+
183+
query I
184+
SELECT * from t1 order by '1', 1;
185+
----
186+
1 3
187+
2 1
188+
3 2
189+
190+
statement ok
191+
DROP TABLE if EXISTS t1

0 commit comments

Comments
 (0)