]> granicus.if.org Git - postgresql/commitdiff
Make OFF keyword unreserved. It's not hard to imagine wanting to use 'off'
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 22 Oct 2010 14:37:38 +0000 (17:37 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 22 Oct 2010 14:44:50 +0000 (17:44 +0300)
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
src/include/parser/kwlist.h

index 609c4727017429e09f3679ad0bc60c4a84185a69..71315c5480854d0cadb0c69f7202fc0e3a8aa19a 100644 (file)
@@ -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
index d3ea04b7f4a4026712e71d8666f1bac94161f42c..2c44cf7943cdec5742eec1b7d2f8680c5ea59796 100644 (file)
@@ -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)