docs+test: skip_duplicates enforces secondary unique constraints on PostgreSQL (fixes #1049)#1417
Open
dimitri-yatsenko wants to merge 1 commit intomasterfrom
Open
docs+test: skip_duplicates enforces secondary unique constraints on PostgreSQL (fixes #1049)#1417dimitri-yatsenko wants to merge 1 commit intomasterfrom
dimitri-yatsenko wants to merge 1 commit intomasterfrom
Conversation
…nstraints Resolves #1049 — on PostgreSQL, skip_duplicates=True already enforces secondary unique constraints (ON CONFLICT (pk) DO NOTHING targets only the primary key). On MySQL, ON DUPLICATE KEY UPDATE catches all unique keys, silently skipping secondary violations too. Changes: - Update insert() docstring to document the backend difference. - Add integration tests covering: PK-only skip, secondary unique violation on PostgreSQL (raises), MySQL silent skip (documented asymmetry), composite unique indexes, batch inserts with mixed duplicates, and tables without secondary unique indexes. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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
Resolves #1049.
No new
skip_duplicatesmodes are needed. PostgreSQL already enforces secondary unique constraints whenskip_duplicates=True, because the generated SQL targets only the primary key:This PR documents the behavior and adds integration tests proving it works.
Backend difference (documented, not changed)
MySQL's
ON DUPLICATE KEY UPDATEcatches all unique key conflicts. This is a known asymmetry documented in the updatedinsert()docstring.Changes
table.py: Updatedskip_duplicatesdocstring to explain the PostgreSQL vs MySQL difference.test_skip_duplicates.py: New integration test file with 6 tests (x 2 backends = 12 runs, 4 backend-specific skips):test_skip_duplicates_pk_match-- PK dup silently skipped (both backends)test_skip_duplicates_unique_violation_raises_on_postgres-- new PK + conflicting unique raises (PG only)test_skip_duplicates_unique_on_mysql-- documents MySQL silent skip behaviortest_skip_duplicates_no_unique_index-- works normally without secondary indexestest_skip_duplicates_composite_unique-- composite unique index enforced (PG only)test_skip_duplicates_batch_mixed-- batch with PK dups + unique conflict (PG only)Test plan
Generated with Claude Code