25P02: in_failed_sql_transaction
PostgreSQLWhat does it mean?
An error already occurred earlier in the transaction; no further commands can run in it. The transaction is in the aborted state and only ROLLBACK is accepted.
Why does it happen?
A previous statement in a transaction block failed (e.g. a constraint violation) and new commands keep being sent in the same transaction anyway. The application does not catch the error and carries on with the transaction.
How to fix it
Roll back the transaction: ROLLBACK, then start it again. If you want to isolate a block's error and continue, use SAVEPOINT and return to that point with ROLLBACK TO SAVEPOINT. In the application, catch each statement's error and manage the transaction properly (make the commit/rollback decision explicit).