Is there a way to roll back to a "committed savepoint"?
Afaik, the actual savepoints supported by postgresql are subtransactions and lose their meaning when the enclosing transaction commits or aborts. Are there "savepoints" across transaction boundaries?
Basically, what I want is execute these three transaction in order:
Transaction ~ A
BEGIN TRANSACTION;
COMMIT SAVEPOINT 'before_a';
DO SOMETHING;
COMMIT TRANSACTION;
Transaction ~ B
BEGIN TRANSACTION;
DO SOMETHING_ELSE;
COMMIT TRANSACTION;
Transaction ~ C
BEGIN TRANSACTION
ROLLBACK TO COMMITED SAVEPOINT 'before_a'; -- discards work done in A and B
COMMIT TRANSACTION
The reason is that I am writing a (Java) regression test.
Under faulty circumstances, DO SOMETHING_ELSE
will trigger a transaction commit exception when trying to commit B (some foreign key constraint violations upon a DELETE, I believe), but ONLY if the work done in transaction A has been committed.
As the issue is now resolved, Transaction B will commit. But in doing so, both A and B will have left some by-products in the database. These need now be purged from the database if the next test is supposed to have any chance at succeeding.
It's exceedingly difficult to track these by-products down manually, so transaction C should remove these.