Repository navigation
fix(deparser): quote without/nulls/format column names before types - #400
Conversation
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
🧹 Nitpicks (1) — 🟢 1 low
This PR fixes deparse output for columns whose names collide with PostgreSQL keywords in a pre-type context, plus the fixtures and test wiring to lock the behavior in. The fix is narrowly scoped to the deparser's identifier quoting path, with the rest of the change being generated fixture data and a new kitchen-sink test file.
Reviewed commit: 07301aa |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
Adds six keyword-named-column fixtures to the deparser kitchen-sink suite and a quoteTypedIdentifier guard in packages/deparser/src/deparser.ts that quotes without, nulls, and format column names when followed by a type name, fixing parse conflicts in deparse output.
Key findings
- 🟡 Case-sensitive check misses mixed-case
Withoutbefore type — deparser.ts:2789
| if (typeName && (name === 'without' || name === 'nulls' || name === 'format')) { | ||
| return `"${name}"`; | ||
| } |
There was a problem hiding this comment.
🟡 bug · medium
Case-sensitive check misses mixed-case Without before type
quoteTypedIdentifier compares the name exactly against lowercase 'without'/'nulls'/'format' (packages/deparser/src/deparser.ts:2789), but PostgreSQL matches keywords case-insensitively in the lexer. A column named Without, NULLS, or Format followed by a type name deparses unquoted, because the fallback QuoteUtils.quoteIdentifier also leaves unreserved keywords bare via the lowercasing keywordKindOf lookup. The mixed-case round-trip therefore hits exactly the parse conflict this helper was added to fix for lowercase names.
📋 Prompt for AI Agents
In packages/deparser/src/deparser.ts, quoteTypedIdentifier (around lines 2787-2793), change the condition name === 'without' || name === 'nulls' || name === 'format' to compare name.toLowerCase() against the same keyword set, so mixed-case identifiers like Without/NULLS/Format are also force-quoted when a typeName follows. PostgreSQL's lexer matches keywords case-insensitively, so unquoted mixed-case output reproduces the same parse failure this helper exists to prevent.
…e-keyword-columns # Conflicts: # __fixtures__/generated/generated.json
Summary
CREATE TABLE t ("without" time)deparsed asCREATE TABLE t (without time), which PG's lexer lookahead reads asWITHOUT TIMEand fails to reparse. Same fornulls(→NULLS FIRST/LAST) andformat(→FORMAT JSON).Adds
quoteTypedIdentifier(name, typeName): when a name is followed by a type and is one ofwithout/nulls/format, it is always quoted; otherwise falls back toQuoteUtils.quoteIdentifier. Used forColumnDef(CREATE TABLE, ALTER ... ADD COLUMN, pretty-printed column lists),FunctionParameter, and XMLTABLE columns. General identifier quoting is unchanged.Tests: new kitchen-sink fixture
__fixtures__/kitchen-sink/misc/keyword-column-names.sql(CREATE TABLE, arrays, ALTER ADD COLUMN, XMLTABLE, RETURNS TABLE) with regeneratedgenerated.jsonand round-trip test file.Implemented in session Quote keyword column names before types in deparser
Review with Devin · Open in Devin Desktop
Summary by CodeRabbit
WITHOUT,NULLS, andFORMAT. These names are now quoted appropriately in table definitions, table alterations, function declarations, and XML table column declarations, helping preserve valid SQL syntax when keyword-like names appear alongside type and clause syntax.