Doesn't Differentiate Using Aliases in Group By
See original GitHub issueThe test that I used was:
sql = """SELECT
table_schema
, CASE WHEN table_schema = 'my_table' THEN 1 ELSE 0 END as test
, COUNT(*)
FROM information_schema.columns
GROUP BY
table_schema
, test
LIMIT 10 """
print(sqlglot.transpile(sql, read='postgres', write='oracle', identify=True, pretty=True)[0])
And what it returned was:
SELECT
"table_schema",
CASE
WHEN "table_schema" = 'my_table'
THEN 1
ELSE 0
END AS "test",
COUNT(*)
FROM "information_schema"."columns"
GROUP BY
"table_schema",
"test"
LIMIT 10
Referencing aliases in the group by is not supported in Oracle SQL, so this returns an error
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
SQL - using alias in Group By - Stack Overflow
For most relational database systems, this order explains which names (columns or aliases) are valid because they must have been introduced in a...
Read more >Use column alias in GROUP BY - DBA Stack Exchange
Aliases can be used only if they were introduced in the preceding step. So aliases in the SELECT clause can be used in...
Read more >Why doesn't SQL allow using ALIAS in group by? - Quora
One solution is to define aliases in a subquery, then they can be used anywhere in the main query.
Read more >Is it possible to alias a GROUP BY expression? If not, I don't ...
One major concern with aliases for example is that you then need some kind of name resolution preference - to decide whether to...
Read more >SQL: ALIASES - TechOnTheNet
It is acceptable to use spaces when you are aliasing a column name. However, it is not generally good practice to use spaces...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@barakalon sounds good to me, should i reopen this issue?
@tobymao @barakalon Awesome, thank you!