Skip to content

fix(splitter): keep create-as CTEs attached - #793

Open
edjubert wants to merge 1 commit into
supabase-community:mainfrom
edjubert:edjubert/splitter-create-as-with-cte
Open

fix(splitter): keep create-as CTEs attached#793
edjubert wants to merge 1 commit into
supabase-community:mainfrom
edjubert:edjubert/splitter-create-as-with-cte

Conversation

@edjubert

@edjubert edjubert commented Sep 10, 2026

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

CREATE TABLE AS, CREATE MATERIALIZED VIEW AS, and CREATE VIEW AS
statements whose query starts with a CTE are split before the final query.

This leaves PostgreSQL with an incomplete CREATE ... AS WITH ... fragment and
produces a syntax error at end of input diagnostic.

What is the new behavior?

The statement splitter now keeps a CTE attached to its enclosing CREATE ... AS
statement.

It also preserves WITH (...) DDL options and correctly ends the CTE statement
at its semicolon, without absorbing the following SQL statement.

Additional context

Added regression coverage for:

  • CREATE TABLE AS WITH ...;
  • CREATE MATERIALIZED VIEW AS WITH ...;
  • CREATE VIEW AS WITH ...;
  • CREATE VIEW WITH (...) AS WITH ...;
  • a CTE followed by another statement.

Validated with:

cargo test -p pgls_statement_splitter
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings

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