Fix dropped DML/DDL clauses in statement formatting#39
Conversation
Several INSERT/UPDATE/DELETE and CREATE TABLE/VIEW clauses were silently dropped because their CST nodes were never read in stmt.rs. Read and emit them, keeping river and left-aligned rendering consistent with existing clauses. - #27: emit UPDATE ... FROM (reuses river/left-aligned relation list) - #28: emit INSERT ... ON CONFLICT ... DO UPDATE/DO NOTHING - #29: emit INSERT INTO t DEFAULT VALUES (was invalid INSERT INTO t) - #30: emit RETURNING for INSERT, UPDATE and DELETE - #31: emit DELETE ... USING - #33: emit CREATE TABLE IF NOT EXISTS, INHERITS, PARTITION BY, TABLESPACE - #34: emit CREATE [OR REPLACE] [TEMP] VIEW modifiers (was hardcoded) - #35: emit INSERT ... OVERRIDING {SYSTEM|USER} VALUE Adds river regression fixtures for each case; all outputs verified as valid, idempotent PostgreSQL. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (31)
📝 WalkthroughWalkthroughThis PR fixes the SQL formatter so previously dropped clauses are now emitted correctly for INSERT (OVERRIDING VALUE, ON CONFLICT, RETURNING, DEFAULT VALUES), UPDATE (FROM, RETURNING), DELETE (USING, RETURNING), CREATE TABLE (IF NOT EXISTS, INHERITS, PARTITION BY, TABLESPACE), and CREATE VIEW (OR REPLACE, TEMP). New fixtures validate each clause. ChangesStatement formatter clause fixes
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
Summary
Fixes eight bugs in
src/formatter/stmt.rswhere DML/DDL clauses were silently dropped during formatting, producing incomplete or invalid SQL.Problem
Several statement clauses have CST nodes that the formatters never read, so they were discarded on output:
UPDATE ... FROMlost theFROMclause (UPDATE ... FROM clause is silently dropped #27)INSERT ... ON CONFLICTwas dropped entirely (INSERT ... ON CONFLICT clause is silently dropped #28)INSERT INTO t DEFAULT VALUESbecame the invalidINSERT INTO t(INSERT INTO t DEFAULT VALUES formats to invalid SQL (clause dropped) #29)RETURNINGwas dropped from INSERT, UPDATE, and DELETE (RETURNING clause is dropped from INSERT, UPDATE, and DELETE #30)DELETE ... USINGlost theUSINGclause (DELETE ... USING clause is silently dropped #31)CREATE TABLEdroppedIF NOT EXISTS,INHERITS,PARTITION BY, andTABLESPACE(CREATE TABLE drops IF NOT EXISTS, INHERITS, PARTITION BY, and TABLESPACE clauses #33)CREATE VIEWdroppedOR REPLACEandTEMP/TEMPORARY(name was hardcoded to "CREATE VIEW") (CREATE VIEW drops OR REPLACE and TEMP/TEMPORARY modifiers #34)INSERT ... OVERRIDING {SYSTEM|USER} VALUEwas dropped (INSERT ... OVERRIDING {SYSTEM|USER} VALUE is silently dropped #35)Solution
Read the previously-ignored CST nodes and emit each clause, keeping both river and left-aligned rendering consistent with the surrounding clauses:
format_relation_list_river/_left_alignedhelpers to render an UPDATEFROMlist and a DELETEUSINGlist.format_on_conflict(handlesDO NOTHING,DO UPDATE SET ..., conflict target, optionalWHERE) and areturning_texthelper shared by all three DML statements.FROM/USING/RETURNINGin the river-width computation so alignment stays correct.CREATE TABLEnow emitsIF NOT EXISTSin the header andINHERITS/PARTITION BY/TABLESPACEafter the column list;CREATE VIEWbuilds its prefix from the actualOR REPLACEandOptTempnodes.Added a river regression fixture pair for each case under
tests/fixtures/river/. All new outputs were verified to be valid, idempotent PostgreSQL.cargo fmt,cargo clippy -- -D warnings, andcargo testall pass.Fixes #27
Fixes #28
Fixes #29
Fixes #30
Fixes #31
Fixes #33
Fixes #34
Fixes #35
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
INSERT,UPDATE,DELETE,CREATE TABLE, andCREATE VIEW.RETURNING, conflict actions,USING/FROMclauses, table inheritance, partitioning, tablespaces, and view variations like temporary and replaceable views.Bug Fixes