[Solved] PostgreSQL Error: ERROR: CURRENT TRANSACTION IS ABORTED, COMMANDS IGNORED UNTIL END OF TRANSA

Error occurred:

Current transaction is aborted, commands ignored until end of transaction block

analysis:

The transaction contains errors. When the DML is executed again, the transaction cannot proceed normally.

When automatic transaction submission is turned off in PG database, we often encounter such problems
error:   Current transaction is aborted, commands ignored until end of transaction block
the reason why this problem is caused is that
in the Postgres database, if an error occurs in a database operation in the same transaction, the database after the transaction will make an error
let’s take a very simple example
test = # select * from test1
ERROR:   relation “test1” does not exist
LINE 1: select * from test1;
^
time: 0.376 MS
at this time, because there is no operation error, all subsequent operations in this session will report
error:   Current transaction is aborted, commands ignored until end of transaction block
to solve this problem, we can only use rollback or commit
PG is not user-friendly
Solution:

1. Try connection.setautocommit (true); Cannot execute

2. Commit directly, execute the insert statement after submitting, and insert successfully.

Refer to the stackoverflow solution:

postgresql – PSQLException: current transaction is aborted, commands ignored until end of transaction block – Stack Overflow

Read More: