Skip to content

Commit 1e5588c

Browse files
committed
Allow type_func_name_keywords in some places where they weren't before.
This change makes type_func_name_keywords less reserved than they were before, by allowing them for role names, language names, EXPLAIN and COPY options, and SET values for GUCs; which are all places where few if any actual keywords could appear instead, so no new ambiguities are introduced. The main driver for this change is to allow "COPY ... (FORMAT BINARY)" to work without quoting the word "binary". That is an inconsistency that has been complained of repeatedly over the years (at least by Pavel Golub, Kurt Lidl, and Simon Riggs); but we hadn't thought of any non-ugly solution until now. Back-patch to 9.0 where the COPY (FORMAT BINARY) syntax was introduced.
1 parent 39485bb commit 1e5588c

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/backend/parser/gram.y

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,10 @@ static void processCASbits(int cas_bits, int location, const char *constrType,
426426

427427
%type <ival> Iconst SignedIconst
428428
%type <str> Sconst comment_text notify_payload
429-
%type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
429+
%type <str> RoleId opt_granted_by opt_boolean_or_string
430430
%type <list> var_list
431431
%type <str> ColId ColLabel var_name type_function_name param_name
432+
%type <str> NonReservedWord NonReservedWord_or_Sconst
432433
%type <node> var_value zone_value
433434

434435
%type <keyword> unreserved_keyword type_func_name_keyword
@@ -1321,15 +1322,15 @@ set_rest: /* Generic SET syntaxes: */
13211322
n->kind = VAR_SET_DEFAULT;
13221323
$$ = n;
13231324
}
1324-
| ROLE ColId_or_Sconst
1325+
| ROLE NonReservedWord_or_Sconst
13251326
{
13261327
VariableSetStmt *n = makeNode(VariableSetStmt);
13271328
n->kind = VAR_SET_VALUE;
13281329
n->name = "role";
13291330
n->args = list_make1(makeStringConst($2, @2));
13301331
$$ = n;
13311332
}
1332-
| SESSION AUTHORIZATION ColId_or_Sconst
1333+
| SESSION AUTHORIZATION NonReservedWord_or_Sconst
13331334
{
13341335
VariableSetStmt *n = makeNode(VariableSetStmt);
13351336
n->kind = VAR_SET_VALUE;
@@ -1383,11 +1384,11 @@ opt_boolean_or_string:
13831384
| FALSE_P { $$ = "false"; }
13841385
| ON { $$ = "on"; }
13851386
/*
1386-
* OFF is also accepted as a boolean value, but is handled
1387-
* by the ColId rule below. The action for booleans and strings
1387+
* OFF is also accepted as a boolean value, but is handled by
1388+
* the NonReservedWord rule. The action for booleans and strings
13881389
* is the same, so we don't need to distinguish them here.
13891390
*/
1390-
| ColId_or_Sconst { $$ = $1; }
1391+
| NonReservedWord_or_Sconst { $$ = $1; }
13911392
;
13921393

13931394
/* Timezone values can be:
@@ -1456,8 +1457,8 @@ opt_encoding:
14561457
| /*EMPTY*/ { $$ = NULL; }
14571458
;
14581459

1459-
ColId_or_Sconst:
1460-
ColId { $$ = $1; }
1460+
NonReservedWord_or_Sconst:
1461+
NonReservedWord { $$ = $1; }
14611462
| Sconst { $$ = $1; }
14621463
;
14631464

@@ -3177,7 +3178,7 @@ NumericOnly_list: NumericOnly { $$ = list_make1($1); }
31773178
*****************************************************************************/
31783179

31793180
CreatePLangStmt:
3180-
CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3181+
CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
31813182
{
31823183
CreatePLangStmt *n = makeNode(CreatePLangStmt);
31833184
n->replace = $2;
@@ -3189,7 +3190,7 @@ CreatePLangStmt:
31893190
n->pltrusted = false;
31903191
$$ = (Node *)n;
31913192
}
3192-
| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
3193+
| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
31933194
HANDLER handler_name opt_inline_handler opt_validator
31943195
{
31953196
CreatePLangStmt *n = makeNode(CreatePLangStmt);
@@ -3233,15 +3234,15 @@ opt_validator:
32333234
;
32343235

32353236
DropPLangStmt:
3236-
DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
3237+
DROP opt_procedural LANGUAGE NonReservedWord_or_Sconst opt_drop_behavior
32373238
{
32383239
DropPLangStmt *n = makeNode(DropPLangStmt);
32393240
n->plname = $4;
32403241
n->behavior = $5;
32413242
n->missing_ok = false;
32423243
$$ = (Node *)n;
32433244
}
3244-
| DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
3245+
| DROP opt_procedural LANGUAGE IF_P EXISTS NonReservedWord_or_Sconst opt_drop_behavior
32453246
{
32463247
DropPLangStmt *n = makeNode(DropPLangStmt);
32473248
n->plname = $6;
@@ -3341,11 +3342,11 @@ create_extension_opt_item:
33413342
{
33423343
$$ = makeDefElem("schema", (Node *)makeString($2));
33433344
}
3344-
| VERSION_P ColId_or_Sconst
3345+
| VERSION_P NonReservedWord_or_Sconst
33453346
{
33463347
$$ = makeDefElem("new_version", (Node *)makeString($2));
33473348
}
3348-
| FROM ColId_or_Sconst
3349+
| FROM NonReservedWord_or_Sconst
33493350
{
33503351
$$ = makeDefElem("old_version", (Node *)makeString($2));
33513352
}
@@ -3374,7 +3375,7 @@ alter_extension_opt_list:
33743375
;
33753376

33763377
alter_extension_opt_item:
3377-
TO ColId_or_Sconst
3378+
TO NonReservedWord_or_Sconst
33783379
{
33793380
$$ = makeDefElem("new_version", (Node *)makeString($2));
33803381
}
@@ -5061,8 +5062,8 @@ SecLabelStmt:
50615062
}
50625063
;
50635064

5064-
opt_provider: FOR ColId_or_Sconst { $$ = $2; }
5065-
| /* empty */ { $$ = NULL; }
5065+
opt_provider: FOR NonReservedWord_or_Sconst { $$ = $2; }
5066+
| /* empty */ { $$ = NULL; }
50665067
;
50675068

50685069
security_label_type:
@@ -6051,7 +6052,7 @@ createfunc_opt_item:
60516052
{
60526053
$$ = makeDefElem("as", (Node *)$2);
60536054
}
6054-
| LANGUAGE ColId_or_Sconst
6055+
| LANGUAGE NonReservedWord_or_Sconst
60556056
{
60566057
$$ = makeDefElem("language", (Node *)makeString($2));
60576058
}
@@ -6260,7 +6261,7 @@ dostmt_opt_item:
62606261
{
62616262
$$ = makeDefElem("as", (Node *)makeString($1));
62626263
}
6263-
| LANGUAGE ColId_or_Sconst
6264+
| LANGUAGE NonReservedWord_or_Sconst
62646265
{
62656266
$$ = makeDefElem("language", (Node *)makeString($2));
62666267
}
@@ -7918,9 +7919,7 @@ explain_option_elem:
79187919
;
79197920

79207921
explain_option_name:
7921-
ColId { $$ = $1; }
7922-
| analyze_keyword { $$ = "analyze"; }
7923-
| VERBOSE { $$ = "verbose"; }
7922+
NonReservedWord { $$ = $1; }
79247923
;
79257924

79267925
explain_option_arg:
@@ -11781,7 +11780,7 @@ AexprConst: Iconst
1178111780

1178211781
Iconst: ICONST { $$ = $1; };
1178311782
Sconst: SCONST { $$ = $1; };
11784-
RoleId: ColId { $$ = $1; };
11783+
RoleId: NonReservedWord { $$ = $1; };
1178511784

1178611785
SignedIconst: Iconst { $$ = $1; }
1178711786
| '+' Iconst { $$ = + $2; }
@@ -11813,6 +11812,14 @@ type_function_name: IDENT { $$ = $1; }
1181311812
| type_func_name_keyword { $$ = pstrdup($1); }
1181411813
;
1181511814

11815+
/* Any not-fully-reserved word --- these names can be, eg, role names.
11816+
*/
11817+
NonReservedWord: IDENT { $$ = $1; }
11818+
| unreserved_keyword { $$ = pstrdup($1); }
11819+
| col_name_keyword { $$ = pstrdup($1); }
11820+
| type_func_name_keyword { $$ = pstrdup($1); }
11821+
;
11822+
1181611823
/* Column label --- allowed labels in "AS" clauses.
1181711824
* This presently includes *all* Postgres keywords.
1181811825
*/

0 commit comments

Comments
 (0)