diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 69c4fa442fa..a8ff1d1ce46 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -401,9 +401,10 @@ static TypeName *TableFuncTypeName(List *columns); %type Iconst SignedIconst %type Sconst comment_text notify_payload -%type RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst +%type RoleId opt_granted_by opt_boolean_or_string %type var_list %type ColId ColLabel var_name type_function_name param_name +%type NonReservedWord NonReservedWord_or_Sconst %type var_value zone_value %type unreserved_keyword type_func_name_keyword @@ -1275,7 +1276,7 @@ set_rest: /* Generic SET syntaxes: */ n->kind = VAR_SET_DEFAULT; $$ = n; } - | ROLE ColId_or_Sconst + | ROLE NonReservedWord_or_Sconst { VariableSetStmt *n = makeNode(VariableSetStmt); n->kind = VAR_SET_VALUE; @@ -1283,7 +1284,7 @@ set_rest: /* Generic SET syntaxes: */ n->args = list_make1(makeStringConst($2, @2)); $$ = n; } - | SESSION AUTHORIZATION ColId_or_Sconst + | SESSION AUTHORIZATION NonReservedWord_or_Sconst { VariableSetStmt *n = makeNode(VariableSetStmt); n->kind = VAR_SET_VALUE; @@ -1337,11 +1338,11 @@ opt_boolean_or_string: | FALSE_P { $$ = "false"; } | ON { $$ = "on"; } /* - * OFF is also accepted as a boolean value, but is handled - * by the ColId rule below. The action for booleans and strings + * OFF is also accepted as a boolean value, but is handled by + * the NonReservedWord rule. The action for booleans and strings * is the same, so we don't need to distinguish them here. */ - | ColId_or_Sconst { $$ = $1; } + | NonReservedWord_or_Sconst { $$ = $1; } ; /* Timezone values can be: @@ -1410,8 +1411,8 @@ opt_encoding: | /*EMPTY*/ { $$ = NULL; } ; -ColId_or_Sconst: - ColId { $$ = $1; } +NonReservedWord_or_Sconst: + NonReservedWord { $$ = $1; } | Sconst { $$ = $1; } ; @@ -2894,7 +2895,7 @@ NumericOnly_list: NumericOnly { $$ = list_make1($1); } *****************************************************************************/ CreatePLangStmt: - CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst + CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst { CreatePLangStmt *n = makeNode(CreatePLangStmt); n->replace = $2; @@ -2906,7 +2907,7 @@ CreatePLangStmt: n->pltrusted = false; $$ = (Node *)n; } - | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst + | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst HANDLER handler_name opt_inline_handler opt_validator { CreatePLangStmt *n = makeNode(CreatePLangStmt); @@ -2950,7 +2951,7 @@ opt_validator: ; DropPLangStmt: - DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior + DROP opt_procedural LANGUAGE NonReservedWord_or_Sconst opt_drop_behavior { DropPLangStmt *n = makeNode(DropPLangStmt); n->plname = $4; @@ -2958,7 +2959,7 @@ DropPLangStmt: n->missing_ok = false; $$ = (Node *)n; } - | DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior + | DROP opt_procedural LANGUAGE IF_P EXISTS NonReservedWord_or_Sconst opt_drop_behavior { DropPLangStmt *n = makeNode(DropPLangStmt); n->plname = $6; @@ -5256,7 +5257,7 @@ createfunc_opt_item: { $$ = makeDefElem("as", (Node *)$2); } - | LANGUAGE ColId_or_Sconst + | LANGUAGE NonReservedWord_or_Sconst { $$ = makeDefElem("language", (Node *)makeString($2)); } @@ -5465,7 +5466,7 @@ dostmt_opt_item: { $$ = makeDefElem("as", (Node *)makeString($1)); } - | LANGUAGE ColId_or_Sconst + | LANGUAGE NonReservedWord_or_Sconst { $$ = makeDefElem("language", (Node *)makeString($2)); } @@ -6978,9 +6979,7 @@ explain_option_elem: ; explain_option_name: - ColId { $$ = $1; } - | analyze_keyword { $$ = "analyze"; } - | VERBOSE { $$ = "verbose"; } + NonReservedWord { $$ = $1; } ; explain_option_arg: @@ -10776,7 +10775,7 @@ AexprConst: Iconst Iconst: ICONST { $$ = $1; }; Sconst: SCONST { $$ = $1; }; -RoleId: ColId { $$ = $1; }; +RoleId: NonReservedWord { $$ = $1; }; SignedIconst: Iconst { $$ = $1; } | '+' Iconst { $$ = + $2; } @@ -10808,6 +10807,14 @@ type_function_name: IDENT { $$ = $1; } | type_func_name_keyword { $$ = pstrdup($1); } ; +/* Any not-fully-reserved word --- these names can be, eg, role names. + */ +NonReservedWord: IDENT { $$ = $1; } + | unreserved_keyword { $$ = pstrdup($1); } + | col_name_keyword { $$ = pstrdup($1); } + | type_func_name_keyword { $$ = pstrdup($1); } + ; + /* Column label --- allowed labels in "AS" clauses. * This presently includes *all* Postgres keywords. */