Skip to main content

unwrap_unnest_generate_series_for_postgres

Function unwrap_unnest_generate_series_for_postgres 

Source
pub fn unwrap_unnest_generate_series_for_postgres(
    expr: Expression,
) -> Result<Expression>
Expand description

Convert UNNEST(GENERATE_SERIES(start, end, step)) to a subquery for PostgreSQL.

PostgreSQL’s GENERATE_SERIES returns rows directly, so UNNEST wrapping is unnecessary. Instead, convert to:

(SELECT CAST(value AS DATE) FROM GENERATE_SERIES(start, end, step) AS _t(value)) AS _unnested_generate_series

This handles the case where GENERATE_DATE_ARRAY was converted to GENERATE_SERIES during cross-dialect normalization, but the original had UNNEST wrapping.