From 5c84fe4607907b22e45433195fec800d23ac1f49 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas <heikki.linnakangas@iki.fi> Date: Fri, 22 Oct 2010 17:37:38 +0300 Subject: [PATCH] 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. --- src/backend/parser/gram.y | 26 +++++++++++++------------- src/include/parser/kwlist.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 609c4727017..71315c54808 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -402,7 +402,7 @@ static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_ %type <ival> Iconst SignedIconst %type <str> Sconst comment_text notify_payload -%type <str> RoleId opt_granted_by opt_boolean ColId_or_Sconst +%type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst %type <list> var_list %type <str> ColId ColLabel var_name type_function_name param_name %type <node> var_value zone_value @@ -1326,9 +1326,7 @@ var_list: var_value { $$ = list_make1($1); } | var_list ',' var_value { $$ = lappend($1, $3); } ; -var_value: opt_boolean - { $$ = makeStringConst($1, @1); } - | ColId_or_Sconst +var_value: opt_boolean_or_string { $$ = makeStringConst($1, @1); } | NumericOnly { $$ = makeAConst($1, @1); } @@ -1340,11 +1338,16 @@ iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; } | SERIALIZABLE { $$ = "serializable"; } ; -opt_boolean: +opt_boolean_or_string: TRUE_P { $$ = "true"; } | FALSE_P { $$ = "false"; } | ON { $$ = "on"; } - | OFF { $$ = "off"; } + /* + * OFF is also accepted as a boolean value, but is handled + * by the ColId rule below. The action for booleans and strings + * is the same, so we don't need to distinguish them here. + */ + | ColId_or_Sconst { $$ = $1 } ; /* Timezone values can be: @@ -2239,8 +2242,7 @@ copy_generic_opt_elem: ; copy_generic_opt_arg: - opt_boolean { $$ = (Node *) makeString($1); } - | ColId_or_Sconst { $$ = (Node *) makeString($1); } + opt_boolean_or_string { $$ = (Node *) makeString($1); } | NumericOnly { $$ = (Node *) $1; } | '*' { $$ = (Node *) makeNode(A_Star); } | '(' copy_generic_opt_arg_list ')' { $$ = (Node *) $2; } @@ -2260,8 +2262,7 @@ copy_generic_opt_arg_list: /* beware of emitting non-string list elements here; see commands/define.c */ copy_generic_opt_arg_list_item: - opt_boolean { $$ = (Node *) makeString($1); } - | ColId_or_Sconst { $$ = (Node *) makeString($1); } + opt_boolean_or_string { $$ = (Node *) makeString($1); } ; @@ -7158,8 +7159,7 @@ explain_option_name: ; explain_option_arg: - opt_boolean { $$ = (Node *) makeString($1); } - | ColId_or_Sconst { $$ = (Node *) makeString($1); } + opt_boolean_or_string { $$ = (Node *) makeString($1); } | NumericOnly { $$ = (Node *) $1; } | /* EMPTY */ { $$ = NULL; } ; @@ -11184,6 +11184,7 @@ unreserved_keyword: | NULLS_P | OBJECT_P | OF + | OFF | OIDS | OPERATOR | OPTION @@ -11443,7 +11444,6 @@ reserved_keyword: | LOCALTIMESTAMP | NOT | NULL_P - | OFF | OFFSET | ON | ONLY diff --git a/src/include/parser/kwlist.h b/src/include/parser/kwlist.h index d3ea04b7f4a..2c44cf7943c 100644 --- a/src/include/parser/kwlist.h +++ b/src/include/parser/kwlist.h @@ -262,7 +262,7 @@ PG_KEYWORD("nulls", NULLS_P, UNRESERVED_KEYWORD) PG_KEYWORD("numeric", NUMERIC, COL_NAME_KEYWORD) PG_KEYWORD("object", OBJECT_P, UNRESERVED_KEYWORD) PG_KEYWORD("of", OF, UNRESERVED_KEYWORD) -PG_KEYWORD("off", OFF, RESERVED_KEYWORD) +PG_KEYWORD("off", OFF, UNRESERVED_KEYWORD) PG_KEYWORD("offset", OFFSET, RESERVED_KEYWORD) PG_KEYWORD("oids", OIDS, UNRESERVED_KEYWORD) PG_KEYWORD("on", ON, RESERVED_KEYWORD) -- GitLab