There Was an Error in a Good Query
After applying a data migration we had some duplicated rows in a table. I wrote a simple query for finding the duplicates and removing them from the table. All went fine. Or at least I thought so.
This kind of operations should always be done in a transaction, so the changes can be rolled back on error. The general workflow I use looks like this:
BEGIN; DELETE FROM x... SELECT * FROM x... ...
This leaves an open transaction, so I can check all the data without modifying them permanently in the database.