linter: fix adding-not-nullable-field for pg >= 12 with validated CHECK#910
Open
reteps wants to merge 1 commit intosbdchd:masterfrom
Open
linter: fix adding-not-nullable-field for pg >= 12 with validated CHECK#910reteps wants to merge 1 commit intosbdchd:masterfrom
reteps wants to merge 1 commit intosbdchd:masterfrom
Conversation
For PostgreSQL 12+, when there's a validated CHECK constraint that ensures a column IS NOT NULL (e.g., `CHECK (col IS NOT NULL)`), the subsequent `SET NOT NULL` operation can skip the full table scan. This fix tracks CHECK constraints with NOT VALID that check for `column IS NOT NULL`, and after they are validated via VALIDATE CONSTRAINT, allows the SET NOT NULL without warning. Fixes sbdchd#628 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
👷 Deploy request for squawkhq pending review.Visit the deploys page to approve it
|
Author
|
Disclaimer: I have no idea what I am doing here, but the fix Claude put up looks sensible. If you want to close this out, or use this as a starting point, feel free. |
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
Fixes #628
For PostgreSQL 12+, when there's a validated CHECK constraint that ensures a column
IS NOT NULL(e.g.,CHECK (col IS NOT NULL)), the subsequentSET NOT NULLoperation can skip the full table scan because PostgreSQL can use the validated constraint to verify the invariant.This fix tracks CHECK constraints with
NOT VALIDthat check forcolumn IS NOT NULL, and after they are validated viaVALIDATE CONSTRAINT, allows theSET NOT NULLwithout warning.Changes
ADD CONSTRAINT ... CHECK (column IS NOT NULL) NOT VALIDstatementsVALIDATE CONSTRAINTfor those constraintsadding-not-nullable-fieldwarning whenSET NOT NULLis used on a column with a validated CHECK constraintTest plan
🤖 Generated with Claude Code