Repository navigation
Translate NULLS NOT DISTINCT into a companion unique index - #166
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
A unique constraint or unique index declared
NULLS NOT DISTINCTwas refused, because a SQLite unique index always keeps NULLs apart and dropping the clause would let the replica accept rows PostgreSQL rejects. A schema could therefore not declare a constraint its backend supports.The plain unique key is still emitted, so foreign keys and
ON CONFLICTtargets find it, and a companion unique index named after it with_nndappended encodes each key that can be NULL as(key IS NULL, ifnull(key, 0)), keeping the column's collation and a partial index's predicate. NULL keys then collide as an ordinary unique violation, whichINSERT OR IGNOREandON CONFLICT DO NOTHINGskip as PostgreSQL does. A trigger raising on anISmatch would have aborted those and surfaced as a trigger error.DROP INDEXdrops the companion as well, read from the schema as it stood before the drop, and an unnamedNULLS NOT DISTINCTindex is refused since its companion would have no name to follow.ON CONFLICT (key) DO UPDATEstill aborts on a repeated NULL key where PostgreSQL updates the row, since SQLite resolves that target to the plain index. The README lists it under semantic differences.