cockroachdb / cockroachdb/cockroach

plpgsql: properly handle COMMIT/ROLLBACK in nested procedures

Open
#122,266 1 comment 0 reactions 0 assignees View on GitHub
A-sql-plpgsql A-sql-routine C-bug docs-done docs-known-limitation O-qa T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Postgres allows using `COMMIT/ROLLBACK` in nested routines under the following conditions (from the [docs](https://www.postgresql.org/docs/current/plpgsql-transactions.html)):
```
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.
```
In the long term, we should allow `COMMIT/ROLLBACK` in this case, and check for intervening statements to produce the correct error. For 24.1, we should just disallow a nested routine from using `COMMIT/ROLLBACK` entirely.

Jira issue: CRDB-37782

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.