3 ms·
One thing to keep in mind with Postgres is that unique key indices can lead to deadlock and stall other transactions that insert the same key.[1] I wouldn't sa
by rusbus 9y ago
One thing to keep in mind with Postgres is that unique key indices can lead to deadlock and stall other transactions that insert the same key.[1]
I wouldn't say "unique constraints considered harmful" but I would definitely say they can be surprising and must be used with care.
[1]: https://rcoh.me/posts/postgres-unique-constraints-deadlock/ https://rcoh.me/posts/postgres-unique-constraints-deadlock/
- lobster_johnson 9y agoThe relatively new "INSERT ... ON CONFLICT" mechanism is a great way to circumvent this issue. Using that feature, you can tell it to ignore conflicting dupes, or you can have it transform the insert into an update.