fix(deparser): emit CREATE INDEX trailing clauses in grammar order - #336
Merged
Conversation
NULLS NOT DISTINCT now follows the column/INCLUDE list and WHERE moves after WITH/TABLESPACE, so partial unique indexes survive round-trip.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IndexStmtemitted trailing clauses as( params ) → INCLUDE → WHERE → WITH → NULLS NOT DISTINCT → TABLESPACE, which the PG grammar rejects: any partial index withNULLS NOT DISTINCT, or any index with bothWHEREandWITH/TABLESPACE, deparsed into SQL that fails to reparse (syntax error at or near "NULLS"). This broke round-trip validation in@pgsql/transform, and with itgenerate:constructivein constructive-db (constructive-planning#1382).Reordered to the grammar's order —
nulls_not_distinctright after the column/INCLUDElist,whereClauselast:Before / after for the real-world shape:
New round-trip fixtures in
__fixtures__/kitchen-sink/misc/index-clause-ordering.sql(regenerated vianpm run kitchen-sink) cover every clause combination —NULLS NOT DISTINCTalone, withWHERE, withINCLUDE/WITH/TABLESPACE, theWHERE-after-WITHcase withoutNULLS, and the constraint path (UNIQUE NULLS NOT DISTINCT (a, b)) which was already correct.Link to Devin session: https://app.devin.ai/sessions/6e8bd0b058a944eeba4a3dbad12d8487
Requested by: @pyramation