8000 Allow type_func_name_keywords in some places where they weren't before. · sqlparser/postgres@805730d · GitHub
[go: up one dir, main page]

Skip to content

Commit 805730d

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 1b192fc commit 805730d

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/backend/parser/gram.y

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,10 @@ static TypeName *TableFuncTypeName(List *columns);
401401

402402
%type <ival> Iconst SignedIconst
403403
%type <str> Sconst comment_text notify_payload
404-
%type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
404+
%type <str> RoleId opt_granted_by opt_boolean_or_string
405405
%type <list> var_list
406406
%type <str> ColId ColLabel var_name type_function_name param_name
407+
%type <str> NonReservedWord NonReservedWord_or_Sconst
407408
%type <node> var_value zone_value
408409

409410
%type <keyword> unreserved_keyword type_func_name_keyword
@@ -1275,15 +1276,15 @@ set_rest: /* Generic SET syntaxes: */
12751276
n->kind = VAR_SET_DEFAULT;
12761277
$$ = n;
12771278
}
1278-
| ROLE ColId_or_Sconst
1279+
| ROLE NonReservedWord_or_Sconst
12791280
{
12801281
VariableSetStmt *n = makeNode(VariableSetStmt);
12811282
n->kind = VAR_SET_VALUE;
12821283
n->name = "role";
12831284
n->args = list_make1(makeStringConst($2, @2));
12841285
$$ = n;
12851286
}
1286-
| SESSION AUTHORIZATION ColId_or_Sconst
1287+
| SESSION AUTHORIZATION NonReservedWord_or_Sconst
12871288
{
12881289
VariableSetStmt *n = makeNode(VariableSetStmt);
12891290
n->kind = VAR_SET_VALUE;
@@ -1337,11 +1338,11 @@ opt_boolean_or_string:
13371338
| FALSE_P { $$ = "false"; }
13381339
| ON { $$ = "on"; }
13391340
/*
1340-
* OFF is also accepted as a boolean value, but is handled
1341-
* by the ColId rule below. The action for booleans and strings
1341+
* OFF is also accepted as a boolean value, but is handled by
1342+
* the NonReservedWord rule. The action for booleans and strings
13421343
* is the same, so we don't need to distinguish them here.
13431344
*/
1344-
| ColId_or_Sconst { $$ = $1; }
1345+
| NonReservedWord_or_Sconst { $$ = $1; }
13451346
;
13461347

13471348
/* Timezone values can be:
@@ -1410,8 +1411,8 @@ opt_encoding:
14101411
| /*EMPTY*/ { $$ = NULL; }
14111412
;
14121413

1413-
ColId_or_Sconst:
1414-
ColId { $$ = $1; }
1414+
NonReservedWord_or_Sconst:
1415+
NonReservedWord { $$ = $1; }
14151416
| Sconst { $$ = $1; }
14161417
;
14171418

@@ -2894,7 +2895,7 @@ NumericOnly_list: NumericOnly { $$ = list_make1($1); }
28942895
*****************************************************************************/
28952896

28962897
CreatePLangStmt:
2897-
CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2898+
CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
28982899
{
28992900
CreatePLangStmt *n = makeNode(CreatePLangStmt);
29002901
n->replace = $2;
@@ -2906,7 +2907,7 @@ CreatePLangStmt:
29062907
n->pltrusted = false;
29072908
$$ = (Node *)n;
29082909
}
2909-
| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE ColId_or_Sconst
2910+
| CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE NonReservedWord_or_Sconst
29102911
HANDLER handler_name opt_inline_handler opt_validator
29112912
{
29122913
CreatePLangStmt *n = makeNode(CreatePLangStmt);
@@ -2950,15 +2951,15 @@ opt_validator:
29502951
;
29512952

29522953
DropPLangStmt:
2953-
DROP opt_procedural LANGUAGE ColId_or_Sconst opt_drop_behavior
2954+
DROP opt_procedural LANGUAGE NonReservedWord_or_Sconst opt_drop_behavior
29542955
{
29552956
DropPLangStmt *n = makeNode(DropPLangStmt);
29562957
n->plname = $4;
29572958
n->behavior = $5;
29582959
n->missing_ok = false;
29592960
$$ = (Node *)n;
29602961
}
2961-
| DROP opt_procedural LANGUAGE IF_P EXISTS ColId_or_Sconst opt_drop_behavior
2962+
| DROP opt_procedural LANGUAGE IF_P EXISTS NonReservedWord_or_Sconst opt_drop_behavior
29622963
{
29632964
DropPLangStmt *n = makeNode(DropPLangStmt);
29642965
n->plname = $6;
@@ -5256,7 +5257,7 @@ createfunc_opt_item:
52565257
{
52575258
$$ = makeDefElem("as", (Node *)$2);
52585259
}
5259-
| LANGUAGE ColId_or_Sconst
5260+
| LANGUAGE NonReservedWord_or_Sconst
52605261
{
52615262
$$ = makeDefElem("language", (Node *)makeString($2));
52625263
}
@@ -5465,7 +5466,7 @@ dostmt_opt_item:
54655466
{
54665467
$$ = makeDefElem("as", (Node *)makeString($1));
54675468
}
5468-
| LANGUAGE ColId_or_Sconst
5469+
| LANGUAGE NonReservedWord_or_Sconst
54695470
{
54705471
$$ = makeDefElem("language", (Node *)makeString($2));
54715472
}
@@ -6978,9 +6979,7 @@ explain_option_elem:
69786979
;
69796980

69806981
explain_option_name:
6981-
ColId { $$ = $1; }
6982-
| analyze_keyword { $$ = "analyze"; }
6983-
| VERBOSE { $$ = "verbose"; }
6982+
NonReservedWord { $$ = $1; }
69846983
;
69856984

69866985
explain_option_arg:
@@ -10776,7 +10775,7 @@ AexprConst: Iconst
1077610775

1077710776
Iconst: ICONST { $$ = $1; };
1077810777
Sconst: SCONST { $$ = $1; };
10779-
RoleId: ColId { $$ = $1; };
10778+
RoleId: NonReservedWord { $$ = $1; };
1078010779

1078110780
SignedIconst: Iconst { $$ = $1; }
1078210781
| '+' Iconst { $$ = + $2; }
@@ -10808,6 +10807,14 @@ type_function_name: IDENT { $$ = $1; }
1080810807
| type_func_name_keyword { $$ = pstrdup($1); }
1080910808
;
1081010809

10810+
/* Any not-fully-reserved word --- these names can be, eg, role names.
10811+
*/
10812+
NonReservedWord: IDENT { $$ = $1; }
10813+
| unreserved_keyword { $$ = pstrdup($1); }
10814+
| col_name_keyword { $$ = pstrdup($1); }
10815+
| type_func_name_keyword { $$ = pstrdup($1); }
10816+
;
10817+
1081110818
/* Column label --- allowed labels in "AS" clauses.
1081210819
* This presently includes *all* Postgres keywords.
1081310820
*/

0 commit comments

Comments
 (0)
0