Skip to content

fix(splitter): support CTE column lists in CREATE ... AS - #804

Open
edjubert wants to merge 2 commits into
supabase-community:mainfrom
edjubert:edjubert/pr-splitter-cte-column-list
Open

edjubert wants to merge 2 commits into
supabase-community:mainfrom
edjubert:edjubert/pr-splitter-cte-column-list

Conversation

@edjubert

@edjubert edjubert commented Sep 16, 2026

Copy link
Copy Markdown

What

The splitter's cte rule expected IDENT AS (. A CTE may also declare its output columns before AS, and that form made the rule bail out, so the statement was cut in two before the final SELECT:

CREATE TABLE ranked_items AS
WITH
    priorities (label, rank) AS (
        VALUES
            ('high', 1),
            ('medium', 2),
            ('low', 3)
    )
SELECT
    items.id,
    priorities.rank
FROM items
JOIN priorities ON priorities.label = items.priority;

Before this fix, everything up to the closing parenthesis of the CTE was submitted to the parser on its own, which reported syntax error at end of input on a perfectly valid file.

Implementation

Three lines in splitter/dml.rs: consume an optional parenthesised column list between the CTE name and AS.

Why here

This extends fix(splitter): keep create-as CTEs attached, whose test only covers a CTE whose body is a SELECT.
The column-list form - most common with VALUES lookup tables — was not covered.

Tests

create_as_with_values_cte in crates/pgls_statement_splitter/src/lib.rs, using the exact statement above, asserting two statements and no errors.

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.

1 participant