If using psql
, you want:
\set ON_ERROR_ROLLBACK on
From the manual:
ON_ERROR_ROLLBACK
When on, if a statement in a transaction block generates an error, the error is ignored and the transaction continues. When interactive, such errors are only ignored in interactive sessions, and not when reading script files. When off (the default), a statement in a transaction block that generates an error aborts the entire transaction