Documentation: What about unique constraints?
See original GitHub issueI am trying to understand what happens during copy_from
if a table already contains data and a unique constraint is triggered.
By using drop_constraints=False
, if a value-to-be-saved already exists in the database will it be ignored or will an error be raised?
Searching the Postgresql-9.5+ docs, I found the ON CONFLICT
clause which caters for this issue.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Documentation: 15: 5.4. Constraints - PostgreSQL
Unique constraints ensure that the data contained in a column, or a group of columns, is unique among all the rows in the...
Read more >Unique Constraints and Check Constraints - SQL Server
UNIQUE constraints and CHECK constraints are two types of constraints that can be used to enforce data integrity in SQL Server tables.
Read more >12.2. Unique Constraints
Unique constraints ensure that the data in a column or combination of columns is unique for each row. A table's primary key, for...
Read more >SQL UNIQUE Constraint - W3Schools
The UNIQUE constraint ensures that all values in a column are different. Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for...
Read more >Unique Constraints - Vertica
You can define a unique constraint that is comprised of multiple columns. The following CREATE TABLE statement specifies that the combined values of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a good question. I do not know the answer. Shall we write a unit test?
Yeah in my opinion the default behavior should always be to raise the IntegrityError but allow users to pass in an
ON CONFLICT DO NOTHING
argument since the latter might have unintended consequences (such a silently omitting rows).Sounds reasonable to me.