[PLSQL] I want to update rows in my Postgres
database if the updated version wouldn't violate the primary key constraint.
Assuming the table has primary keys on col1
, col2
and col3
if I run a query like this:
UPDATE table
SET col2='B'
WHERE col2='E';
'A', 'B', 'C'
'A', 'E', 'C'
'A', 'E', 'D'
The query will fail and I will get a duplicate key error because of the 2nd row.
Instead I want a query that skips the 2nd row which causes PK violation and updates the 3rd row. The required table after the update query will be like the following:
'A', 'B', 'C'
'A', 'E', 'C'
'A', 'B', 'D'