Skip to content

Commit e664969

Browse files
committed
Cause plpgsql to throw an error if "INTO rowtype_var" is followed by a comma.
Per bug #5352, this helps to provide a useful error message if the user tries to do something presently unsupported, namely use a rowtype variable as a member of a multiple-item INTO list.
1 parent 5600aac commit e664969

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/pl/plpgsql/src/gram.y

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.140 2010/01/19 01:35:30 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.141 2010/03/02 16:14:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2881,18 +2881,39 @@ read_into_target(PLpgSQL_rec **rec, PLpgSQL_row **row, bool *strict)
28812881
tok = yylex();
28822882
}
28832883

2884+
/*
2885+
* Currently, a row or record variable can be the single INTO target,
2886+
* but not a member of a multi-target list. So we throw error if there
2887+
* is a comma after it, because that probably means the user tried to
2888+
* write a multi-target list. If this ever gets generalized, we should
2889+
* probably refactor read_into_scalar_list so it handles all cases.
2890+
*/
28842891
switch (tok)
28852892
{
28862893
case T_DATUM:
28872894
if (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_ROW)
28882895
{
28892896
check_assignable(yylval.wdatum.datum, yylloc);
28902897
*row = (PLpgSQL_row *) yylval.wdatum.datum;
2898+
2899+
if ((tok = yylex()) == ',')
2900+
ereport(ERROR,
2901+
(errcode(ERRCODE_SYNTAX_ERROR),
2902+
errmsg("record or row variable cannot be part of multiple-item INTO list"),
2903+
parser_errposition(yylloc)));
2904+
plpgsql_push_back_token(tok);
28912905
}
28922906
else if (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_REC)
28932907
{
28942908
check_assignable(yylval.wdatum.datum, yylloc);
28952909
*rec = (PLpgSQL_rec *) yylval.wdatum.datum;
2910+
2911+
if ((tok = yylex()) == ',')
2912+
ereport(ERROR,
2913+
(errcode(ERRCODE_SYNTAX_ERROR),
2914+
errmsg("record or row variable cannot be part of multiple-item INTO list"),
2915+
parser_errposition(yylloc)));
2916+
plpgsql_push_back_token(tok);
28962917
}
28972918
else
28982919
{

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