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

Support CROSS JOIN UNNEST() #21180

Open
FallenerFurtherstr opened this issue Feb 11, 2025 · 0 comments
Open

Support CROSS JOIN UNNEST() #21180

FallenerFurtherstr opened this issue Feb 11, 2025 · 0 comments
Labels
A-sql Area: Polars SQL functionality enhancement New feature or an improvement of an existing feature

Comments

@FallenerFurtherstr
Copy link

FallenerFurtherstr commented Feb 11, 2025

Description

Hi everyone! I'm new to Polars, and already enjoying sqling lazyframes. I was trying to unnest a column of array into multiple rows of data, just like what CROSS JOIN UNNEST() does in Postgre SQL. So I tried to execute following sql sentence as an example:

WITH sequence AS
(
    SELECT 1 AS id, [0, 1, 2] AS numbers
    UNION ALL SELECT 2 AS id, [4, 6] AS numbers
)
Select id, flattened_numbers
FROM sequences
CROSS JOIN UNNEST(numbers) AS flattened_numbers

This example should yield a result like this:

id numbers
1 0
1 1
1 2
2 4
2 6

But upon executing this, it throws an error:

polars.exceptions.SQLSyntaxError: Expected array expression, found Identifier(Ident { value: "numbers", quote_style: None, span: Span(Location(9, 23)..Location(9, 30)) })

Seems that Polars doesn't implement this feature (looks like UNNEST always wants an array), or I just do it in a wrong way. Since this operation doesn't affect the overall schema (i.e. it doesn't add new columns, but rows), it would greatly enhance the sql feature if it's possible to do so.

EDIT: Remove redundant header

@FallenerFurtherstr FallenerFurtherstr added the enhancement New feature or an improvement of an existing feature label Feb 11, 2025
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql Area: Polars SQL functionality enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants