Skip to content

fix: handle AS [NOT] MATERIALIZED in CTE statement splitting#696

Merged
psteinroe merged 1 commit intosupabase-community:mainfrom
reteps:reteps/fix-materialized
Feb 27, 2026
Merged

fix: handle AS [NOT] MATERIALIZED in CTE statement splitting#696
psteinroe merged 1 commit intosupabase-community:mainfrom
reteps:reteps/fix-materialized

Conversation

@reteps
Copy link
Copy Markdown
Contributor

@reteps reteps commented Feb 26, 2026

Note: This PR was generated with Claude.

Summary

  • Fix spurious "Expected L_PAREN" syntax error when using AS MATERIALIZED (...) or AS NOT MATERIALIZED (...) in CTEs (PostgreSQL 12+ feature)
  • The statement splitter's cte() function went directly from AS to expecting (, not accounting for the optional [NOT] MATERIALIZED hint
  • Added p.eat(NOT_KW) and p.eat(MATERIALIZED_KW) between AS and the parenthesized subquery

Test plan

  • Added with_cte_as_materialized test — AS MATERIALIZED (...)
  • Added with_cte_as_not_materialized test — AS NOT MATERIALIZED (...)
  • Added with_multiple_materialized_ctes test — mix of plain, materialized, and not-materialized CTEs
  • All 44 statement splitter tests pass
  • No clippy warnings
  • Verified the fix against a real-world SQL file that previously triggered the error

🤖 Generated with Claude Code

The statement splitter did not account for the optional [NOT]
MATERIALIZED hint between AS and ( in CTE definitions, causing a
spurious "Expected L_PAREN" syntax error on valid PostgreSQL 12+ SQL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@reteps
Copy link
Copy Markdown
Contributor Author

reteps commented Feb 26, 2026

Please use that as a bug report/starting point, feel free to push directly to this branch, etc.

Copy link
Copy Markdown
Collaborator

@psteinroe psteinroe left a comment

Choose a reason for hiding this comment

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

thanks!

@psteinroe psteinroe enabled auto-merge (squash) February 27, 2026 07:43
@psteinroe psteinroe merged commit 357b61a into supabase-community:main Feb 27, 2026
9 checks passed
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.

2 participants