Do you need to "ROLLBACK" after an error?

I am new to PostgreSQL / libpq. So please help me clarify my confusion:

Assuming I start by doing "START TRANSACTION" and doing correct error checking (PQresultStatus (res)! = [Proper_success_value]), do I need to do "ROLLBACK" if something goes wrong after typing? For example:

  • START OF TRANSACTION: OK
  • INSERT ..: OK
  • UPDATE ..: FAIL

In this case, do I need to perform a "ROLLBACK" after the "UPDATE" failure? Also, what if "ROLLBACK" also fails?

+3


source to share


1 answer


This is best understood by reading the manual:

https://www.postgresql.org/docs/current/static/tutorial-transactions.html

ROLLBACK TO is the only way to regain control of a block of transactions that was aborted by the system due to an error, except that it completely rolled back and started again.



The rollback should not be interrupted.

Transactions are posted in an aborted state, which means that you cannot do anything in that transaction. You can use a savepoint to restore this transaction, but other than that, all you can do is rollback.

+3


source







All Articles