Question
Equivalent of ON CONFLICT DO NOTHING for UPDATE postgres
I want to update rows in my postgres database if the updated version wouldn't violate the primary key constraint. If it would, I want to leave the row as it is.
Assuming the table has primary keys on col1, col2, col3
, if I run a query like this:
UPDATE table SET (col1, col2) = ('A', 'B')
WHERE col1='D' AND col2='E';
The query will fail and I will get a duplicate key error if there exists two entries:
'A', 'B', 'C'
'D', 'E', 'C'
i.e col3
is the same between an existing row and a row to be updated.
If I was INSERT
ing rows I would use ON CONFLICT DO NOTHING
but I can't find an implementation of this for UPDATE
. Does an equivalent exist?