Skip to content

Commit fe06819

Browse files
committed
Fix psql's ON_ERROR_ROLLBACK so that it handles COMMIT AND CHAIN.
When ON_ERROR_ROLLBACK is enabled, psql releases a temporary savepoint if it's idle in a valid transaction block after executing a query. But psql doesn't do that after RELEASE or ROLLBACK is executed because a temporary savepoint has already been destroyed in that case. This commit changes psql's ON_ERROR_ROLLBACK so that it doesn't release a temporary savepoint also when COMMIT AND CHAIN is executed. A temporary savepoint doesn't need to be released in that case because COMMIT AND CHAIN also destroys any savepoints defined within the transaction to commit. Otherwise psql tries to release the savepoint that COMMIT AND CHAIN has already destroyed and cause an error "ERROR: savepoint "pg_psql_temporary_savepoint" does not exist". Back-patch to v12 where transaction chaining was added. Reported-by: Arthur Nascimento Author: Arthur Nascimento Reviewed-by: Fujii Masao, Vik Fearing Discussion: https://postgr.es/m/16867-3475744069228158@postgresql.org
1 parent 8a55cb5 commit fe06819

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/bin/psql/common.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,13 @@ SendQuery(const char *query)
13501350

13511351
/*
13521352
* Do nothing if they are messing with savepoints themselves:
1353-
* If the user did RELEASE or ROLLBACK, our savepoint is gone.
1354-
* If they issued a SAVEPOINT, releasing ours would remove
1355-
* theirs.
1353+
* If the user did COMMIT AND CHAIN, RELEASE or ROLLBACK, our
1354+
* savepoint is gone. If they issued a SAVEPOINT, releasing
1355+
* ours would remove theirs.
13561356
*/
13571357
if (results &&
1358-
(strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 ||
1358+
(strcmp(PQcmdStatus(results), "COMMIT") == 0 ||
1359+
strcmp(PQcmdStatus(results), "SAVEPOINT") == 0 ||
13591360
strcmp(PQcmdStatus(results), "RELEASE") == 0 ||
13601361
strcmp(PQcmdStatus(results), "ROLLBACK") == 0))
13611362
svptcmd = NULL;

0 commit comments

Comments
 (0)