Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a0899c0

Browse files
committed
Doc: minor improvements for plpgsql "Transaction Management" section.
Point out that savepoint commands cannot be issued in PL/pgSQL, and suggest that exception blocks can usually be used instead. Add a caveat to the discussion of cursor loops vs. transactions, pointing out that any locks taken by the cursor query will be lost at COMMIT. This is implicit in what's already said, but the existing text leaves the distinct impression that the auto-hold behavior is transparent, which it's not really. Per a couple of recent complaints (one unsigned, and one in bug #18531 from Dzmitry Jachnik). Back-patch to v17, just so this makes it into current docs in less than a year-and-a-half. Discussion: https://postgr.es/m/172076354433.736586.14347210271966220018@wrigleys.postgresql.org Discussion: https://postgr.es/m/18531-c6dddd33b8555fd2@postgresql.org
1 parent 8583b1f commit a0899c0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

doc/src/sgml/plpgsql.sgml

+15-5
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,17 @@ CALL transaction_test1();
37453745
<command>SELECT</command> in between.
37463746
</para>
37473747

3748+
<para>
3749+
<application>PL/pgSQL</application> does not support savepoints
3750+
(<command>SAVEPOINT</command>/<command>ROLLBACK TO
3751+
SAVEPOINT</command>/<command>RELEASE SAVEPOINT</command> commands).
3752+
Typical usage patterns for savepoints can be replaced by blocks with
3753+
exception handlers (see <xref linkend="plpgsql-error-trapping"/>).
3754+
Under the hood, a block with exception handlers forms a
3755+
subtransaction, which means that transactions cannot be ended inside
3756+
such a block.
3757+
</para>
3758+
37483759
<para>
37493760
Special considerations apply to cursor loops. Consider this example:
37503761
<programlisting>
@@ -3770,18 +3781,17 @@ CALL transaction_test2();
37703781
evaluated at the first <command>COMMIT</command> or
37713782
<command>ROLLBACK</command> rather than row by row. The cursor is still
37723783
removed automatically after the loop, so this is mostly invisible to the
3773-
user.
3784+
user. But one must keep in mind that any table or row locks taken by
3785+
the cursor's query will no longer be held after the
3786+
first <command>COMMIT</command> or
3787+
<command>ROLLBACK</command>.
37743788
</para>
37753789

37763790
<para>
37773791
Transaction commands are not allowed in cursor loops driven by commands
37783792
that are not read-only (for example <command>UPDATE
37793793
... RETURNING</command>).
37803794
</para>
3781-
3782-
<para>
3783-
A transaction cannot be ended inside a block with exception handlers.
3784-
</para>
37853795
</sect1>
37863796

37873797
<sect1 id="plpgsql-errors-and-messages">

0 commit comments

Comments
 (0)