fix(postgres): support UNIQUE NULLS NOT DISTINCT constraint syntax#839
Merged
NQPhuc merged 2 commits intoholistics:masterfrom Mar 9, 2026
Merged
Conversation
PostgreSQL 15 introduced `NULLS NOT DISTINCT` for unique constraints, allowing NULL values to be treated as equal. The parser grammar was missing this optional clause in the `constraintelem` rule, causing a crash when importing SQL dumps containing this syntax. Fixes holistics#838 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
While waiting for this PR to be merged, I've published a temporary fork to npm: Packages: Version: Usage# Using npx
npx -p @frenzzy/dbml-cli@nulls-not-distinct sql2dbml schema.sql --postgres -o schema.dbml
# Or install as dependency
npm install @frenzzy/dbml-cli@nulls-not-distinctThese are drop-in replacements until the official packages are updated. |
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
Fix
sql2dbmlcrash when parsing PostgreSQL dumps containingUNIQUE NULLS NOT DISTINCTconstraints (introduced in PostgreSQL 15).Root cause: The
constraintelemgrammar rule was missing the optionalnulls_distinct?clause before the column list in theUNIQUEalternative. This caused the ANTLR parser to produce a null node for the column list, leading toCannot read properties of null (reading 'accept')invisitConstraintelem.Fix: Added
nulls_distinct?(which already existed in the grammar forCREATE INDEX) to theUNIQUEbranch ofconstraintelem. TheNULLS NOT DISTINCTmodifier is gracefully ignored in the DBML output, falling back to a regularUNIQUEconstraint — consistent with how DBML currently handles index-levelNULLS NOT DISTINCT.Fixes #838
Changes
PostgreSQLParser.g4: Addednulls_distinct?to theUNIQUEbranch ofconstraintelem(1-line change)PostgreSQLParser.jsandPostgreSQLParser.interpvia ANTLR 4.13.2nulls_not_distinct.in.sql/nulls_not_distinct.out.dbml)Test plan
nulls_not_distincttest case passespg_dumpoutput containingUNIQUE NULLS NOT DISTINCT