Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbf08e65

Browse files
committed
Give a more specific error message for "you can't do that" error cases
in plpgsql, particularly trying to begin/end/rollback a transaction.
1 parent2d65574 commitbf08e65

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.114 2004/08/02 17:03:45 tgl Exp $
6+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.115 2004/08/13 18:47:56 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -2090,8 +2090,29 @@ exec_prepare_plan(PLpgSQL_execstate * estate,
20902090
*/
20912091
plan=SPI_prepare(expr->query,expr->nparams,argtypes);
20922092
if (plan==NULL)
2093-
elog(ERROR,"SPI_prepare failed for \"%s\": %s",
2094-
expr->query,SPI_result_code_string(SPI_result));
2093+
{
2094+
/* Some SPI errors deserve specific error messages */
2095+
switch (SPI_result)
2096+
{
2097+
caseSPI_ERROR_COPY:
2098+
ereport(ERROR,
2099+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2100+
errmsg("cannot COPY to/from client in PL/pgSQL")));
2101+
caseSPI_ERROR_CURSOR:
2102+
ereport(ERROR,
2103+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2104+
errmsg("cannot manipulate cursors directly in PL/pgSQL"),
2105+
errhint("Use PL/pgSQL's cursor features instead.")));
2106+
caseSPI_ERROR_TRANSACTION:
2107+
ereport(ERROR,
2108+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2109+
errmsg("cannot begin/end transactions in PL/pgSQL"),
2110+
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
2111+
default:
2112+
elog(ERROR,"SPI_prepare failed for \"%s\": %s",
2113+
expr->query,SPI_result_code_string(SPI_result));
2114+
}
2115+
}
20952116
expr->plan=SPI_saveplan(plan);
20962117
spi_plan= (_SPI_plan*)expr->plan;
20972118
expr->plan_argtypes=spi_plan->argtypes;
@@ -2272,6 +2293,22 @@ exec_stmt_dynexecute(PLpgSQL_execstate * estate,
22722293
break;
22732294
}
22742295

2296+
/* Some SPI errors deserve specific error messages */
2297+
caseSPI_ERROR_COPY:
2298+
ereport(ERROR,
2299+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2300+
errmsg("cannot COPY to/from client in PL/pgSQL")));
2301+
caseSPI_ERROR_CURSOR:
2302+
ereport(ERROR,
2303+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2304+
errmsg("cannot manipulate cursors directly in PL/pgSQL"),
2305+
errhint("Use PL/pgSQL's cursor features instead.")));
2306+
caseSPI_ERROR_TRANSACTION:
2307+
ereport(ERROR,
2308+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2309+
errmsg("cannot begin/end transactions in PL/pgSQL"),
2310+
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
2311+
22752312
default:
22762313
elog(ERROR,"SPI_exec failed executing query \"%s\": %s",
22772314
querystr,SPI_result_code_string(exec_res));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp