Make OFF keyword unreserved. It's not hard to imagine wanting to use 'off'
authorHeikki Linnakangas
Fri, 22 Oct 2010 14:37:38 +0000 (17:37 +0300)
committerHeikki Linnakangas
Fri, 22 Oct 2010 14:44:36 +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 50ed8716ca863f96001ff943945989150f97e0a9..de91ccc2147602d44967083a27157155c768c647 100644 (file)
@@ -401,7 +401,7 @@ static TypeName *TableFuncTypeName(List *columns);
 
 %type    Iconst SignedIconst
 %type         Sconst comment_text notify_payload
-%type         RoleId opt_granted_by opt_boolean ColId_or_Sconst
+%type         RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
 %type    var_list
 %type         ColId ColLabel var_name type_function_name param_name
 %type    var_value zone_value
@@ -1320,9 +1320,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); }
@@ -1334,11 +1332,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:
@@ -2167,8 +2170,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; }
@@ -2188,8 +2190,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); }
        ;
 
 
@@ -6983,8 +6984,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; }
        ;
@@ -10958,6 +10958,7 @@ unreserved_keyword:
            | NULLS_P
            | OBJECT_P
            | OF
+           | OFF
            | OIDS
            | OPERATOR
            | OPTION
@@ -11214,7 +11215,6 @@ reserved_keyword:
            | LOCALTIMESTAMP
            | NOT
            | NULL_P
-           | OFF
            | OFFSET
            | ON
            | ONLY
index 5065bd609e9a36069a9d40e75f8727526799ef52..ad835d9a7d3c81a71601995737580788df92a606 100644 (file)
@@ -260,7 +260,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)