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

Presto: Transpiling SEQUENCE with alias to UNNEST(SEQUENCE(...)) has incorrect alias #1600

Closed
vegarsti opened this issue May 12, 2023 · 0 comments

Comments

@vegarsti
Copy link
Contributor

vegarsti commented May 12, 2023

#1527 implemented a fix for transpiling SEQUENCE to Presto, so we now wrap SEQUENCE in an UNNEST call if used as a source. But there's an edge case left, where if we original SEQUENCE has an alias, that alias is not translated properly to the Presto code.

Code snippet

>>> import sqlglot
>>> sqlglot.__version__
'12.3.0'
>>> sqlglot.transpile("SELECT * FROM t CROSS JOIN GENERATE_SERIES(2, 4) s", read="postgres", write="presto")[0]
'SELECT * FROM t CROSS JOIN UNNEST(SEQUENCE(2, 4)) AS s'

The unnest requires a tuple (?) alias, so we need s to be _u(s) (like in #1495). Thus the transpiled SQL here should be

SELECT * FROM t CROSS JOIN UNNEST(SEQUENCE(2, 4)) AS _u(s)
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.

1 participant