mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-18 00:54:19 +01:00
Merge 'Make sure explicit column aliases have binding precedence in orderby' from Pavan Nambi
closes https://github.com/tursodatabase/turso/issues/3684 Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #3709
This commit is contained in:
@@ -3451,12 +3451,11 @@ pub fn bind_and_rewrite_expr<'a>(
|
|||||||
if binding_behavior == BindingBehavior::TryResultColumnsFirst {
|
if binding_behavior == BindingBehavior::TryResultColumnsFirst {
|
||||||
if let Some(result_columns) = result_columns {
|
if let Some(result_columns) = result_columns {
|
||||||
for result_column in result_columns.iter() {
|
for result_column in result_columns.iter() {
|
||||||
if result_column
|
if let Some(alias) = &result_column.alias {
|
||||||
.name(referenced_tables)
|
if alias.eq_ignore_ascii_case(&normalized_id) {
|
||||||
.is_some_and(|name| name.eq_ignore_ascii_case(&normalized_id))
|
*expr = result_column.expr.clone();
|
||||||
{
|
return Ok(WalkControl::Continue);
|
||||||
*expr = result_column.expr.clone();
|
}
|
||||||
return Ok(WalkControl::Continue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3553,12 +3552,11 @@ pub fn bind_and_rewrite_expr<'a>(
|
|||||||
if binding_behavior == BindingBehavior::TryCanonicalColumnsFirst {
|
if binding_behavior == BindingBehavior::TryCanonicalColumnsFirst {
|
||||||
if let Some(result_columns) = result_columns {
|
if let Some(result_columns) = result_columns {
|
||||||
for result_column in result_columns.iter() {
|
for result_column in result_columns.iter() {
|
||||||
if result_column
|
if let Some(alias) = &result_column.alias {
|
||||||
.name(referenced_tables)
|
if alias.eq_ignore_ascii_case(&normalized_id) {
|
||||||
.is_some_and(|name| name.eq_ignore_ascii_case(&normalized_id))
|
*expr = result_column.expr.clone();
|
||||||
{
|
return Ok(WalkControl::Continue);
|
||||||
*expr = result_column.expr.clone();
|
}
|
||||||
return Ok(WalkControl::Continue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,4 +239,29 @@ do_execsql_test_on_specific_db {:memory:} orderby_alias_precedence {
|
|||||||
INSERT INTO t VALUES (1,200),(2,100);
|
INSERT INTO t VALUES (1,200),(2,100);
|
||||||
SELECT x AS y, y AS x FROM t ORDER BY x;
|
SELECT x AS y, y AS x FROM t ORDER BY x;
|
||||||
} {2|100
|
} {2|100
|
||||||
1|200}
|
1|200}
|
||||||
|
|
||||||
|
# https://github.com/tursodatabase/turso/issues/3684
|
||||||
|
do_execsql_test_on_specific_db {:memory:} orderby_alias_shadows_column {
|
||||||
|
CREATE TABLE t(a, b);
|
||||||
|
INSERT INTO t VALUES (1, 1), (2, 2), (3, 3);
|
||||||
|
SELECT a, -b AS a FROM t ORDER BY a;
|
||||||
|
} {3|-3
|
||||||
|
2|-2
|
||||||
|
1|-1}
|
||||||
|
|
||||||
|
do_execsql_test_in_memory_any_error order_by_ambiguous_column {
|
||||||
|
CREATE TABLE a(id INT, value INT);
|
||||||
|
INSERT INTO a VALUES (1, 10), (2, 20);
|
||||||
|
|
||||||
|
CREATE TABLE b(id INT, value INT);
|
||||||
|
INSERT INTO b VALUES (1, 100), (2, 200);
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
a.id,
|
||||||
|
b.value
|
||||||
|
FROM
|
||||||
|
a JOIN b ON a.id = b.id
|
||||||
|
ORDER BY
|
||||||
|
value;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user