Skip to content

Commit 143b8cb

Browse files
committed
Make OFF keyword unreserved. It's not hard to imagine wanting to use 'off'
as a variable or column name, and it's not reserved in recent versions of the SQL spec either. This became particularly annoying in 9.0, before that PL/pgSQL replaced variable names in queries with parameter markers, so it was possible to use OFF and many other backend parser keywords as variable names. Because of that, backpatch to 9.0.
1 parent eda3a62 commit 143b8cb

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/backend/parser/gram.y

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static TypeName *TableFuncTypeName(List *columns);
401401

402402
%type <ival> Iconst SignedIconst
403403
%type <str> Sconst comment_text notify_payload
404-
%type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst
404+
%type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
405405
%type <list> var_list
406406
%type <str> ColId ColLabel var_name type_function_name param_name
407407
%type <node> var_value zone_value
@@ -1320,9 +1320,7 @@ var_list: var_value { $$ = list_make1($1); }
13201320
| var_list ',' var_value { $$ = lappend($1, $3); }
13211321
;
13221322

1323-
var_value: opt_boolean
1324-
{ $$ = makeStringConst($1, @1); }
1325-
| ColId_or_Sconst
1323+
var_value: opt_boolean_or_string
13261324
{ $$ = makeStringConst($1, @1); }
13271325
| NumericOnly
13281326
{ $$ = makeAConst($1, @1); }
@@ -1334,11 +1332,16 @@ iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
13341332
| SERIALIZABLE { $$ = "serializable"; }
13351333
;
13361334

1337-
opt_boolean:
1335+
opt_boolean_or_string:
13381336
TRUE_P { $$ = "true"; }
13391337
| FALSE_P { $$ = "false"; }
13401338
| ON { $$ = "on"; }
1341-
| OFF { $$ = "off"; }
1339+
/*
1340+
* OFF is also accepted as a boolean value, but is handled
1341+
* by the ColId rule below. The action for booleans and strings
1342+
* is the same, so we don't need to distinguish them here.
1343+
*/
1344+
| ColId_or_Sconst { $$ = $1 }
13421345
;
13431346

13441347
/* Timezone values can be:
@@ -2167,8 +2170,7 @@ copy_generic_opt_elem:
21672170
;
21682171

21692172
copy_generic_opt_arg:
2170-
opt_boolean { $$ = (Node *) makeString($1); }
2171-
| ColId_or_Sconst { $$ = (Node *) makeString($1); }
2173+
opt_boolean_or_string { $$ = (Node *) makeString($1); }
21722174
| NumericOnly { $$ = (Node *) $1; }
21732175
| '*' { $$ = (Node *) makeNode(A_Star); }
21742176
| '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; }
@@ -2188,8 +2190,7 @@ copy_generic_opt_arg_list:
21882190

21892191
/* beware of emitting non-string list elements here; see commands/define.c */
21902192
copy_generic_opt_arg_list_item:
2191-
opt_boolean { $$ = (Node *) makeString($1); }
2192-
| ColId_or_Sconst { $$ = (Node *) makeString($1); }
2193+
opt_boolean_or_string { $$ = (Node *) makeString($1); }
21932194
;
21942195

21952196

@@ -6983,8 +6984,7 @@ explain_option_name:
69836984
;
69846985

69856986
explain_option_arg:
6986-
opt_boolean { $$ = (Node *) makeString($1); }
6987-
| ColId_or_Sconst { $$ = (Node *) makeString($1); }
6987+
opt_boolean_or_string { $$ = (Node *) makeString($1); }
69886988
| NumericOnly { $$ = (Node *) $1; }
69896989
| /* EMPTY */ { $$ = NULL; }
69906990
;
@@ -10958,6 +10958,7 @@ unreserved_keyword:
1095810958
| NULLS_P
1095910959
| OBJECT_P
1096010960
| OF
10961+
| OFF
1096110962
| OIDS
1096210963
| OPERATOR
1096310964
| OPTION
@@ -11214,7 +11215,6 @@ reserved_keyword:
1121411215
| LOCALTIMESTAMP
1121511216
| NOT
1121611217
| NULL_P
11217-
| OFF
1121811218
| OFFSET
1121911219
| ON
1122011220
| ONLY

src/include/parser/kwlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ PG_KEYWORD("nulls", NULLS_P, UNRESERVED_KEYWORD)
260260
PG_KEYWORD("numeric", NUMERIC, COL_NAME_KEYWORD)
261261
PG_KEYWORD("object", OBJECT_P, UNRESERVED_KEYWORD)
262262
PG_KEYWORD("of", OF, UNRESERVED_KEYWORD)
263-
PG_KEYWORD("off", OFF, RESERVED_KEYWORD)
263+
PG_KEYWORD("off", OFF, UNRESERVED_KEYWORD)
264264
PG_KEYWORD("offset", OFFSET, RESERVED_KEYWORD)
265265
PG_KEYWORD("oids", OIDS, UNRESERVED_KEYWORD)
266266
PG_KEYWORD("on", ON, RESERVED_KEYWORD)

0 commit comments

Comments
 (0)