Skip to content

Commit c9301de

Browse files
committed
Reword SPI_ERROR_TRANSACTION errors in PL/pgSQL
The previous message for SPI_ERROR_TRANSACTION claimed "cannot begin/end transactions in PL/pgSQL", but that is no longer true. Nevertheless, the error can still happen, so reword the messages. The error cases in exec_prepare_plan() could never happen, so remove them.
1 parent a40cff8 commit c9301de

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

src/pl/plpgsql/src/expected/plpgsql_transaction.out

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ $$;
409409
INFO: read committed
410410
INFO: repeatable read
411411
INFO: read committed
412-
-- error case
412+
-- error cases
413413
DO LANGUAGE plpgsql $$
414414
BEGIN
415415
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
@@ -418,6 +418,20 @@ $$;
418418
ERROR: SET TRANSACTION ISOLATION LEVEL must be called before any query
419419
CONTEXT: SQL statement "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ"
420420
PL/pgSQL function inline_code_block line 3 at SET
421+
DO LANGUAGE plpgsql $$
422+
BEGIN
423+
SAVEPOINT foo;
424+
END;
425+
$$;
426+
ERROR: unsupported transaction command in PL/pgSQL
427+
CONTEXT: PL/pgSQL function inline_code_block line 3 at SQL statement
428+
DO LANGUAGE plpgsql $$
429+
BEGIN
430+
EXECUTE 'COMMIT';
431+
END;
432+
$$;
433+
ERROR: EXECUTE of transaction commands is not implemented
434+
CONTEXT: PL/pgSQL function inline_code_block line 3 at EXECUTE
421435
DROP TABLE test1;
422436
DROP TABLE test2;
423437
DROP TABLE test3;

src/pl/plpgsql/src/pl_exec.c

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,27 +3965,8 @@ exec_prepare_plan(PLpgSQL_execstate *estate,
39653965
(void *) expr,
39663966
cursorOptions);
39673967
if (plan == NULL)
3968-
{
3969-
/* Some SPI errors deserve specific error messages */
3970-
switch (SPI_result)
3971-
{
3972-
case SPI_ERROR_COPY:
3973-
ereport(ERROR,
3974-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3975-
errmsg("cannot COPY to/from client in PL/pgSQL")));
3976-
break;
3977-
case SPI_ERROR_TRANSACTION:
3978-
ereport(ERROR,
3979-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3980-
errmsg("cannot begin/end transactions in PL/pgSQL"),
3981-
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
3982-
break;
3983-
default:
3984-
elog(ERROR, "SPI_prepare_params failed for \"%s\": %s",
3985-
expr->query, SPI_result_code_string(SPI_result));
3986-
break;
3987-
}
3988-
}
3968+
elog(ERROR, "SPI_prepare_params failed for \"%s\": %s",
3969+
expr->query, SPI_result_code_string(SPI_result));
39893970
if (keepplan)
39903971
SPI_keepplan(plan);
39913972
expr->plan = plan;
@@ -4129,8 +4110,7 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
41294110
case SPI_ERROR_TRANSACTION:
41304111
ereport(ERROR,
41314112
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4132-
errmsg("cannot begin/end transactions in PL/pgSQL"),
4133-
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
4113+
errmsg("unsupported transaction command in PL/pgSQL")));
41344114
break;
41354115

41364116
default:
@@ -4317,8 +4297,7 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate,
43174297
case SPI_ERROR_TRANSACTION:
43184298
ereport(ERROR,
43194299
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4320-
errmsg("cannot begin/end transactions in PL/pgSQL"),
4321-
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
4300+
errmsg("EXECUTE of transaction commands is not implemented")));
43224301
break;
43234302

43244303
default:

src/pl/plpgsql/src/sql/plpgsql_transaction.sql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,25 @@ BEGIN
335335
END;
336336
$$;
337337

338-
-- error case
338+
-- error cases
339339
DO LANGUAGE plpgsql $$
340340
BEGIN
341341
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
342342
END;
343343
$$;
344344

345+
DO LANGUAGE plpgsql $$
346+
BEGIN
347+
SAVEPOINT foo;
348+
END;
349+
$$;
350+
351+
DO LANGUAGE plpgsql $$
352+
BEGIN
353+
EXECUTE 'COMMIT';
354+
END;
355+
$$;
356+
345357
DROP TABLE test1;
346358
DROP TABLE test2;
347359
DROP TABLE test3;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy