16.4. Example 2 (more than one subtransaction)

The parent transaction can have more than one subtransaction, just by repeating the application of the push/pop cycle.

BEGIN; -- start ordinary tx T0
|
INSERT INTO t VALUES (1);
:\
: BEGIN AUTONOMOUS TRANSACTION; -- start AST tx T1, pushes T0 into stack
: |
: INSERT INTO t VALUES (2);
: |
: COMMIT AUTONOMOUS TRANSACTION / ROLLBACK AUTONOMOUS TRANSACTION; -- ends tx T1, pops tx T0 from stack
:/
|
:\
: BEGIN AUTONOMOUS TRANSACTION; -- start AST tx T2, pushes T0 into stack
: |
: INSERT INTO t VALUES (4);
: |
: COMMIT AUTONOMOUS TRANSACTION / ROLLBACK AUTONOMOUS TRANSACTION; -- ends tx T2, pops tx T0 from stack
:/
COMMIT / ROLLBACK; -- ends tx T0