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

Commita056f14

Browse files
committed
Cause plpgsql's PERFORM to behave according to its documentation,
which says that PERFORM will execute any SELECT query and discard theresult. The former implementation would in fact raise an error if theresult contained more than one row or more than one column.Also, change plpgsql's error-logging mechanism to emit the additionalmessages about error location at NOTICE rather than DEBUG level. Thisallows them to be seen by the client without having to dig into thepostmaster log file (which may be nonexistent or inaccessible by theclient).
1 parent505d903 commita056f14

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

‎doc/src/sgml/plsql.sgml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.34 2001/05/2814:58:58 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.35 2001/05/2819:33:24 tgl Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -1402,15 +1402,12 @@ RAISE EXCEPTION ''Inexistent ID --> %'',user_id;
14021402
error, parse error). And it is possible that the database backend
14031403
is in an inconsistent state at this point so returning to the upper
14041404
executor or issuing more commands might corrupt the whole database.
1405-
And even if, at this point the information, that the transaction
1406-
is aborted, is already sent to the client application, so resuming
1407-
operation does not make any sense.
14081405
</para>
14091406

14101407
<para>
14111408
Thus, the only thing PL/pgSQL currently does when it encounters
14121409
an abort during execution of a function or trigger
1413-
procedure is to write some additionalDEBUG level log messages
1410+
procedure is to write some additionalNOTICE level log messages
14141411
telling in which function and where (line number and type of
14151412
statement) this happened.
14161413
</para>

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

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.43 2001/05/21 14:22:19 wieck Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.44 2001/05/28 19:33:24 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -185,7 +185,7 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
185185
*/
186186
if (error_info_func!=NULL)
187187
{
188-
elog(DEBUG,"Last error occured while executing PL/pgSQL function %s",
188+
elog(NOTICE,"Error occurred while executing PL/pgSQL function %s",
189189
error_info_func->fn_name);
190190
if (error_info_stmt!=NULL)
191191
{
@@ -248,15 +248,15 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo)
248248
stmttype="unknown";
249249
break;
250250
}
251-
elog(DEBUG,"line %d at %s",error_info_stmt->lineno,
251+
elog(NOTICE,"line %d at %s",error_info_stmt->lineno,
252252
stmttype);
253253
}
254254
else
255255
{
256256
if (error_info_text!=NULL)
257-
elog(DEBUG,"%s",error_info_text);
257+
elog(NOTICE,"%s",error_info_text);
258258
else
259-
elog(DEBUG,"no more error information available");
259+
elog(NOTICE,"no more error information available");
260260
}
261261

262262
error_info_func=NULL;
@@ -491,7 +491,7 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
491491
*/
492492
if (error_info_func!=NULL)
493493
{
494-
elog(DEBUG,"Last error occured while executing PL/pgSQL function %s",
494+
elog(NOTICE,"Error occurred while executing PL/pgSQL function %s",
495495
error_info_func->fn_name);
496496
if (error_info_stmt!=NULL)
497497
{
@@ -548,15 +548,15 @@ plpgsql_exec_trigger(PLpgSQL_function * func,
548548
stmttype="unknown";
549549
break;
550550
}
551-
elog(DEBUG,"line %d at %s",error_info_stmt->lineno,
551+
elog(NOTICE,"line %d at %s",error_info_stmt->lineno,
552552
stmttype);
553553
}
554554
else
555555
{
556556
if (error_info_text!=NULL)
557-
elog(DEBUG,"%s",error_info_text);
557+
elog(NOTICE,"%s",error_info_text);
558558
else
559-
elog(DEBUG,"no more error information available");
559+
elog(NOTICE,"no more error information available");
560560
}
561561

562562
error_info_func=NULL;
@@ -1065,15 +1065,41 @@ exec_stmt(PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt)
10651065
/* ----------
10661066
* exec_stmt_assignEvaluate an expression and
10671067
*put the result into a variable.
1068+
*
1069+
* For no very good reason, this is also used for PERFORM statements.
10681070
* ----------
10691071
*/
10701072
staticint
10711073
exec_stmt_assign(PLpgSQL_execstate*estate,PLpgSQL_stmt_assign*stmt)
10721074
{
1073-
if (stmt->varno<0)
1074-
exec_assign_expr(estate,NULL,stmt->expr);
1075+
PLpgSQL_expr*expr=stmt->expr;
1076+
1077+
if (stmt->varno >=0)
1078+
exec_assign_expr(estate,estate->datums[stmt->varno],expr);
10751079
else
1076-
exec_assign_expr(estate,estate->datums[stmt->varno],stmt->expr);
1080+
{
1081+
/*
1082+
* PERFORM: evaluate query and discard result. This cannot share
1083+
* code with the assignment case since we do not wish to constraint
1084+
* the discarded result to be only one row/column.
1085+
*/
1086+
intrc;
1087+
1088+
SPI_tuptable=NULL;
1089+
SPI_processed=0;
1090+
1091+
/*
1092+
* If not already done create a plan for this expression
1093+
*/
1094+
if (expr->plan==NULL)
1095+
exec_prepare_plan(estate,expr);
1096+
1097+
rc=exec_run_select(estate,expr,0,NULL);
1098+
if (rc!=SPI_OK_SELECT)
1099+
elog(ERROR,"query \"%s\" didn't return data",expr->query);
1100+
1101+
SPI_freetuptable(SPI_tuptable);
1102+
}
10771103

10781104
returnPLPGSQL_RC_OK;
10791105
}
@@ -2608,8 +2634,7 @@ exec_assign_expr(PLpgSQL_execstate * estate, PLpgSQL_datum * target,
26082634
boolisnull= false;
26092635

26102636
value=exec_eval_expr(estate,expr,&isnull,&valtype);
2611-
if (target!=NULL)
2612-
exec_assign_value(estate,target,value,valtype,&isnull);
2637+
exec_assign_value(estate,target,value,valtype,&isnull);
26132638

26142639
SPI_freetuptable(SPI_tuptable);
26152640
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp