Skip to content

Conversation

@geooo109
Copy link
Collaborator

@geooo109 geooo109 commented Nov 20, 2025

Fixes #6358

This PR fixes the qualification of GENERATE_SERIES and table as column.

GENERATE_SERIES

SELECT * FROM GENERATE_SERIES(1, 2);
 generate_series 
-----------------
               1
               2
(2 rows)

In postgres GENERATE_SERIES creates a column generate_series, thus in order to safely qualify this we have the two following cases:

  1. Without alias: we just create an alias on optimization time and use the default generate_series column:
SELECT generate_series FROM GENERATE_SERIES(1,2); => SELECT generate_series FROM GENERATE_SERIES(1, 2) AS _q_0(generate_series);
  1. With alias: we wrap it with a generated alias from the optimizer:
SELECT g FROM GENERATE_SERIES(1,2) AS g; => SELECT g FROM GENERATE_SERIES(1, 2) AS _q_0(g);

Table projection
postgres supports:

SELECT t FROM t;

The type of t is record, which is an abstract type. We treat this case as the bigquerry table-column reference.

@geooo109 geooo109 changed the title fix(optimizer): postgres qualify GENERATE_SERIES and table projection fix(optimizer): postgres qualify GENERATE_SERIES and table as column reference Nov 20, 2025
@georgesittas georgesittas marked this pull request as draft November 20, 2025 18:01
@geooo109 geooo109 changed the title fix(optimizer): postgres qualify GENERATE_SERIES and table as column reference fix(optimizer): qualify functions with default columns and tables as column references Nov 24, 2025
@geooo109 geooo109 force-pushed the geooo109/postgres_gen_series branch from 71aa367 to e8994a8 Compare November 24, 2025 19:36
@geooo109 geooo109 marked this pull request as ready for review November 25, 2025 15:02
@geooo109 geooo109 force-pushed the geooo109/postgres_gen_series branch from 46bdab7 to cd483eb Compare November 26, 2025 03:09
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @geooo109! This is breaking.

@VaggelisD VaggelisD force-pushed the geooo109/postgres_gen_series branch from cd483eb to 949b9c1 Compare November 26, 2025 09:23
@VaggelisD VaggelisD changed the title fix(optimizer): qualify functions with default columns and tables as column references fix(optimizer)!: qualify functions with default columns and tables as column references Nov 26, 2025
@VaggelisD VaggelisD merged commit 92ee124 into main Nov 26, 2025
8 checks passed
@VaggelisD VaggelisD deleted the geooo109/postgres_gen_series branch November 26, 2025 09:28
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 this pull request may close these issues.

Using generate_series in postgres with alias

5 participants