0

Is it possible to run/create multiple transactions in one session in postgresql?

BEGIN transaction; --tran1
update  table set b=1; 


BEGIN transaction;  --tran2
update  table set b=2;

COMMIT transaction;
COMMIT transaction;

1 Answer 1

1

Yes, that's called a SAVEPOINT:

BEGIN;
    update  table set b=1; 
    SAVEPOINT my_savepoint;
    update  table set b=2;
    RELEASE SAVEPOINT my_savepoint;
COMMIT;
Sign up to request clarification or add additional context in comments.

3 Comments

Perhaps it should be noted that rolling back the main transaction will automatically roll back the subtransaction.
Unlike tsql, "begin" and "begin transaction" are same statement for postgresql? Is it correct?
@ArcilTralleis: Please check the manual: postgresql.org/docs/current/sql-begin.html The answer is Yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.