Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snowflake -> duckdb ordered listagg transpilation error #3350

Closed
btyuhas opened this issue Apr 25, 2024 · 0 comments · Fixed by #3352
Closed

snowflake -> duckdb ordered listagg transpilation error #3350

btyuhas opened this issue Apr 25, 2024 · 0 comments · Fixed by #3352
Assignees

Comments

@btyuhas
Copy link

btyuhas commented Apr 25, 2024

DuckDB doesn't use the WITHIN GROUP syntax to order a listagg output. Its instead added into the function call like listagg(col, sep ORDER BY col2)

Fully reproducible code snippet

snowsql = """
    select
        col0,
        listagg(col1, ', ') within group (order by col2)
    from (values
        (1, 'a', 3),
        (2, 'b', 2),
        (3, 'c', 1)
    )
    group by col0
"""
ducksql = sqlglot.transpile(snowsql, read='snowflake', write='duckdb')[0]
print(ducksql)

yields

SELECT col0, GROUP_CONCAT(col1, ', ') WITHIN GROUP (ORDER BY col2) FROM (VALUES (1, 'a', 3), (2, 'b', 2), (3, 'c', 1)) GROUP BY col0

which throws ParserException: Parser Error: Unknown ordered aggregate "GROUP_CONCAT".

I would expect the transpiler to output this:

select
    col0,
    group_concat(col1, ', ' order by col2)
from (values
    (1, 'a', 3),
    (1, 'b', 2),
    (1, 'c', 1)
)
group by col0

Official Documentation

https://duckdb.org/docs/sql/aggregates
https://docs.snowflake.com/en/sql-reference/functions/listagg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants