How to roll back a transaction on error in PostgreSQL?
I'm writing a script for PostgreSQL and since I want it to be executed atomically, I'm wrapping it inside a transaction. I expected the script to look something like this: BEGIN -- 1) Execute some valid actions; -- 2) Execute some action that causes an error. EXCEPTION WHEN OTHERS THEN ROLLBACK; END; -- A.k.a. COMMIT; However, in this case pgAdmin warns me a