question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation: What about unique constraints?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
palewirecommented, Apr 11, 2018

This is a good question. I do not know the answer. Shall we write a unit test?

1reaction
igncampacommented, Apr 13, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found