Skip to content

feat(typecheck): typecheck CREATE … AS query bodies - #789

Open
edjubert wants to merge 2 commits into
supabase-community:mainfrom
edjubert:edjubert/typecheck-create-as-query
Open

feat(typecheck): typecheck CREATE … AS query bodies#789
edjubert wants to merge 2 commits into
supabase-community:mainfrom
edjubert:edjubert/typecheck-create-as-query

Conversation

@edjubert

@edjubert edjubert commented Sep 10, 2026

Copy link
Copy Markdown

What kind of change does this PR introduce?

Feature.

What is the current behavior?

Typechecking skips the query body of CREATE TABLE AS, CREATE MATERIALIZED VIEW AS,
and CREATE VIEW AS.

As a result, database errors inside the embedded SELECT are not reported.

Fixes #786.

What is the new behavior?

The typechecker now extracts and prepares the inner query of supported CREATE … AS
statements without executing the outer DDL.

PostgreSQL diagnostics are mapped back to their original positions in the enclosing
SQL document. Valid create-as statements produce no diagnostic and do not create the
target table or view.

Additional context

Added regression coverage for:

  • invalid columns and relations in CREATE TABLE AS;
  • invalid columns in materialized views and views;
  • valid create-as queries without DDL side effects;
  • workspace-level file-relative diagnostic offsets.

Validated with:

cargo test -p pgls_typecheck
cargo test -p pgls_workspace test_create_as_typecheck_diagnostic_offsets
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings

Extract and prepare the query body of CREATE TABLE AS, CREATE MATERIALIZED VIEW
AS, and CREATE VIEW statements, then map PostgreSQL diagnostics back into the
outer statement.
Verify that the inner create-query offset and the enclosing statement offset
compose into the correct file-relative diagnostic range.
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.

Typecheck skips the SELECT inside CREATE TABLE AS / CREATE MATERIALIZED VIEW / CREATE VIEW

1 participant