Trap Exception in POSTGRESQL script
You set a savepoint and after the comand a Rollback 


CREATE tABLE tablename (blah varchar(3), thing varchar(3))




BEGIN;
SAVEPOINT my_savepoint;
   UPDATE tablename
   SET blah = 'xxx'
   WHERE thing= '123';
ROLLBACK TO my_savepoint;
COMMIT;


db&lt;&gt;fiddle here