Skip to content

Commit 399da7d

Browse files
committed
Fix thinko in tok_is_keyword(): it was looking at the wrong union variant
of YYSTYPE, and hence returning the wrong answer for cases where a plpgsql "unreserved keyword" really does conflict with a variable name. Obviously I didn't test this enough :-(. Per bug #5524 from Peter Gagarinov.
1 parent 3bdd239 commit 399da7d

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/pl/plpgsql/src/gram.y

Lines changed: 3 additions & 3 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.142 2010/03/03 01:53:17 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/gram.y,v 1.143 2010/06/25 16:40:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2080,8 +2080,8 @@ tok_is_keyword(int token, union YYSTYPE *lval,
20802080
* match composite names (hence an unreserved word followed by "."
20812081
* will not be recognized).
20822082
*/
2083-
if (!lval->word.quoted && lval->word.ident != NULL &&
2084-
strcmp(lval->word.ident, kw_str) == 0)
2083+
if (!lval->wdatum.quoted && lval->wdatum.ident != NULL &&
2084+
strcmp(lval->wdatum.ident, kw_str) == 0)
20852085
return true;
20862086
}
20872087
return false; /* not the keyword */

src/test/regress/expected/plpgsql.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,6 +3578,20 @@ $$ language plpgsql;
35783578
select raise_test();
35793579
ERROR: RAISE without parameters cannot be used outside an exception handler
35803580
CONTEXT: PL/pgSQL function "raise_test"
3581+
-- check cases where implicit SQLSTATE variable could be confused with
3582+
-- SQLSTATE as a keyword, cf bug #5524
3583+
create or replace function raise_test() returns void as $$
3584+
begin
3585+
perform 1/0;
3586+
exception
3587+
when sqlstate '22012' then
3588+
raise notice using message = sqlstate;
3589+
raise sqlstate '22012' using message = 'substitute message';
3590+
end;
3591+
$$ language plpgsql;
3592+
select raise_test();
3593+
NOTICE: 22012
3594+
ERROR: substitute message
35813595
drop function raise_test();
35823596
-- test CASE statement
35833597
create or replace function case_test(bigint) returns text as $$

src/test/regress/sql/plpgsql.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,20 @@ $$ language plpgsql;
29162916

29172917
select raise_test();
29182918

2919+
-- check cases where implicit SQLSTATE variable could be confused with
2920+
-- SQLSTATE as a keyword, cf bug #5524
2921+
create or replace function raise_test() returns void as $$
2922+
begin
2923+
perform 1/0;
2924+
exception
2925+
when sqlstate '22012' then
2926+
raise notice using message = sqlstate;
2927+
raise sqlstate '22012' using message = 'substitute message';
2928+
end;
2929+
$$ language plpgsql;
2930+
2931+
select raise_test();
2932+
29192933
drop function raise_test();
29202934

29212935
-- test CASE statement

0 commit comments

Comments
 (0)