Details
Description
create table t1 (a int, b int); |
 |
with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 group by col1) select * from cte; |
so far so good.
prepare st from 'with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 group by col1) select * from cte'; |
execute st; |
ERROR 1054 (42S22): Unknown column 'col1' in 'group statement'
swapping the original column name back in...
prepare st from 'with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 group by a) select * from cte'; |
execute st; |
is OK
order by clause is similar
with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 order by col1) select * from cte; |
is OK.
prepare st from 'with cte (c1,c2) as (select a as col1, sum(b) as col2 from t1 order by col1) select * from cte'; |
execute st; |
ERROR 1054 (42S22): Unknown column 'col1' in 'order clause'
interestingly (by design) the where clause is treated differently
select a as col1, sum(b) as col2 from t1 where col1 is not null; |
ERROR 1054 (42S22): Unknown column 'col1' in 'where clause'
Attachments
Issue Links
- relates to
-
MDEV-32183 Incorrect name resolution in CTE
- Open
-
MDEV-32708 Assertion Failed at /mariadb-11.3.0/sql/filesort.cc:1194
- Closed
-
MDEV-32829 Crash when executing PS for query with eliminated subquery using view
- Closed