Open rad-pat opened 2 days ago
Hi @rad-pat thanks for report this bug.
AS
can't used in group by clause. you can write the SQL like this
select t.col1 as col1, unnest(split(t.col2, ',')) as col2
from t1 as t
group by col1, col2;
Thanks @b41sh. The AS clause in GROUP BY is processed fine in Postgres/Greenplum. It is what is created from SQLAlchemy output. I will have to see if we can adjust this somehow.
Sorry, it seems that SQLAlchemy does not actually output the alias, but it does output the expression and it seems like that fails:
Also, the docs suggest that expression can be used in GROUP BY clause
select t.col1 as col1, unnest(split(t.col2, ',')) as col2
from t1 as t
group by t.col1, unnest(split(t.col2, ','));
SQL Error: Error executing query: SQL: select t.col1 as col1, unnest(split(t.col2, ',')) as col2
from t1 as t
group by t.col1, unnest(split(t.col2, ',')) Query failed: QueryErrors{code=1065, message=error:
--> SQL:3:18
|
1 | select t.col1 as col1, unnest(split(t.col2, ',')) as col2
2 | from t1 as t
3 | group by t.col1, unnest(split(t.col2, ','))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ set-returning functions can only be used in SELECT
} cause: null
Sorry, it seems that SQLAlchemy does not actually output the alias, but it does output the expression and it seems like that fails:
Also, the docs suggest that expression can be used in GROUP BY clause
select t.col1 as col1, unnest(split(t.col2, ',')) as col2 from t1 as t group by t.col1, unnest(split(t.col2, ',')); SQL Error: Error executing query: SQL: select t.col1 as col1, unnest(split(t.col2, ',')) as col2 from t1 as t group by t.col1, unnest(split(t.col2, ',')) Query failed: QueryErrors{code=1065, message=error: --> SQL:3:18 | 1 | select t.col1 as col1, unnest(split(t.col2, ',')) as col2 2 | from t1 as t 3 | group by t.col1, unnest(split(t.col2, ',')) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ set-returning functions can only be used in SELECT } cause: null
This is indeed a problem, I will fix this to allow set returning function in the group by clause.
Search before asking
Version
v1.2.659-nightly
What's Wrong?
Following on from https://github.com/databendlabs/databend/issues/16797 The SQL below still does not work
And also this SQL additionally does not work
How to Reproduce?
No response
Are you willing to submit PR?