Skip to content

Commit 77e0d7b

Browse files
committed
Instead of trying (and failing) to allow <<label>> at the end of a DECLARE
section, throw an error message saying explicitly that the label must go before DECLARE. Per investigation of a recent pgsql-novice question, this code did not work as intended in any modern PG version, maybe not ever. Allowing such a thing would only create ambiguity anyway, so it seems better to remove it than fix it.
1 parent 7c55be7 commit 77e0d7b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/pl/plpgsql/src/gram.y

Lines changed: 17 additions & 13 deletions
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.141 2010/03/02 16:14:39 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.142 2010/03/03 01:53:17 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -170,7 +170,6 @@ static List *read_raise_options(void);
170170
%type <datum> decl_cursor_args
171171
%type <list> decl_cursor_arglist
172172
%type <nsitem> decl_aliasitem
173-
%type <str> decl_stmts decl_stmt
174173

175174
%type <expr> expr_until_semi expr_until_rightbracket
176175
%type <expr> expr_until_then expr_until_loop opt_expr_until_when
@@ -386,10 +385,7 @@ decl_sect : opt_block_label
386385
| opt_block_label decl_start decl_stmts
387386
{
388387
plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
389-
if ($3 != NULL)
390-
$$.label = $3;
391-
else
392-
$$.label = $1;
388+
$$.label = $1;
393389
/* Remember variables declared in decl_stmts */
394390
$$.n_initvars = plpgsql_add_initdatums(&($$.initvarnos));
395391
}
@@ -408,17 +404,25 @@ decl_start : K_DECLARE
408404
;
409405

410406
decl_stmts : decl_stmts decl_stmt
411-
{ $$ = $2; }
412407
| decl_stmt
413-
{ $$ = $1; }
414408
;
415409

416-
decl_stmt : LESS_LESS any_identifier GREATER_GREATER
417-
{ $$ = $2; }
410+
decl_stmt : decl_statement
418411
| K_DECLARE
419-
{ $$ = NULL; }
420-
| decl_statement
421-
{ $$ = NULL; }
412+
{
413+
/* We allow useless extra DECLAREs */
414+
}
415+
| LESS_LESS any_identifier GREATER_GREATER
416+
{
417+
/*
418+
* Throw a helpful error if user tries to put block
419+
* label just before BEGIN, instead of before DECLARE.
420+
*/
421+
ereport(ERROR,
422+
(errcode(ERRCODE_SYNTAX_ERROR),
423+
errmsg("block label must be placed before DECLARE, not after"),
424+
parser_errposition(@1)));
425+
}
422426
;
423427

424428
decl_statement : decl_varname decl_const decl_datatype decl_notnull decl_defval

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