From d92bc83c48bdea9888e64cf1e2edbac9693099c9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 24 Mar 2018 10:05:06 -0400 Subject: PL/pgSQL: Nested CALL with transactions So far, a nested CALL or DO in PL/pgSQL would not establish a context where transaction control statements were allowed. This fixes that by handling CALL and DO specially in PL/pgSQL, passing the atomic/nonatomic execution context through and doing the required management around transaction boundaries. Reviewed-by: Tomas Vondra --- doc/src/sgml/plpgsql.sgml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 7ed926fd51e..b63b8496c7b 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -3463,9 +3463,9 @@ END LOOP label ; Transaction Management - In procedures invoked by the CALL command from the top - level as well as in anonymous code blocks (DO command) - called from the top level, it is possible to end transactions using the + In procedures invoked by the CALL command + as well as in anonymous code blocks (DO command), + it is possible to end transactions using the commands COMMIT and ROLLBACK. A new transaction is started automatically after a transaction is ended using these commands, so there is no separate START @@ -3495,6 +3495,20 @@ CALL transaction_test1(); + + Transaction control is only possible in CALL or + DO invocations from the top level or nested + CALL or DO invocations without any + other intervening command. For example, if the call stack is + CALL proc1()CALL proc2() + → CALL proc3(), then the second and third + procedures can perform transaction control actions. But if the call stack + is CALL proc1()SELECT + func2()CALL proc3(), then the last + procedure cannot do transaction control, because of the + SELECT in between. + + A transaction cannot be ended inside a loop over a query result, nor inside a block with exception handlers. -- cgit v1.2.3