Skip to content

Commit f2eede9

Browse files
committed
Allow type_func_name_keywords in even more places
A while back, 2c92eda allowed type_func_name_keywords to be used in more places, including role identifiers. Unfortunately, that commit missed out on cases where name_list was used for lists-of-roles, eg: for DROP ROLE. This resulted in the unfortunate situation that you could CREATE a role with a type_func_name_keywords-allowed identifier, but not DROP it (directly- ALTER could be used to rename it to something which could be DROP'd). This extends allowing type_func_name_keywords to places where role lists can be used. Back-patch to 9.0, as 2c92eda was.
1 parent e70c428 commit f2eede9

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/backend/parser/gram.y

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static TypeName *TableFuncTypeName(List *columns);
286286
oper_argtypes RuleActionList RuleActionMulti
287287
opt_column_list columnList opt_name_list
288288
sort_clause opt_sort_clause sortby_list index_params
289-
name_list from_clause from_list opt_array_bounds
289+
name_list role_list from_clause from_list opt_array_bounds
290290
qualified_name_list any_name any_name_list
291291
any_operator expr_list attrs
292292
target_list insert_column_list set_target_list
@@ -866,7 +866,7 @@ AlterOptRoleElem:
866866
$$ = makeDefElem("validUntil", (Node *)makeString($3));
867867
}
868868
/* Supported but not documented for roles, for use by ALTER GROUP. */
869-
| USER name_list
869+
| USER role_list
870870
{
871871
$$ = makeDefElem("rolemembers", (Node *)$2);
872872
}
@@ -879,19 +879,19 @@ CreateOptRoleElem:
879879
{
880880
$$ = makeDefElem("sysid", (Node *)makeInteger($2));
881881
}
882-
| ADMIN name_list
882+
| ADMIN role_list
883883
{
884884
$$ = makeDefElem("adminmembers", (Node *)$2);
885885
}
886-
| ROLE name_list
886+
| ROLE role_list
887887
{
888888
$$ = makeDefElem("rolemembers", (Node *)$2);
889889
}
890-
| IN_P ROLE name_list
890+
| IN_P ROLE role_list
891891
{
892892
$$ = makeDefElem("addroleto", (Node *)$3);
893893
}
894-
| IN_P GROUP_P name_list
894+
| IN_P GROUP_P role_list
895895
{
896896
$$ = makeDefElem("addroleto", (Node *)$3);
897897
}
@@ -990,14 +990,14 @@ AlterUserSetStmt:
990990
*****************************************************************************/
991991

992992
DropRoleStmt:
993-
DROP ROLE name_list
993+
DROP ROLE role_list
994994
{
995995
DropRoleStmt *n = makeNode(DropRoleStmt);
996996
n->missing_ok = FALSE;
997997
n->roles = $3;
998998
$$ = (Node *)n;
999999
}
1000-
| DROP ROLE IF_P EXISTS name_list
1000+
| DROP ROLE IF_P EXISTS role_list
10011001
{
10021002
DropRoleStmt *n = makeNode(DropRoleStmt);
10031003
n->missing_ok = TRUE;
@@ -1016,14 +1016,14 @@ DropRoleStmt:
10161016
*****************************************************************************/
10171017

10181018
DropUserStmt:
1019-
DROP USER name_list
1019+
DROP USER role_list
10201020
{
10211021
DropRoleStmt *n = makeNode(DropRoleStmt);
10221022
n->missing_ok = FALSE;
10231023
n->roles = $3;
10241024
$$ = (Node *)n;
10251025
}
1026-
| DROP USER IF_P EXISTS name_list
1026+
| DROP USER IF_P EXISTS role_list
10271027
{
10281028
DropRoleStmt *n = makeNode(DropRoleStmt);
10291029
n->roles = $5;
@@ -1058,7 +1058,7 @@ CreateGroupStmt:
10581058
*****************************************************************************/
10591059

10601060
AlterGroupStmt:
1061-
ALTER GROUP_P RoleId add_drop USER name_list
1061+
ALTER GROUP_P RoleId add_drop USER role_list
10621062
{
10631063
AlterRoleStmt *n = makeNode(AlterRoleStmt);
10641064
n->role = $3;
@@ -1082,14 +1082,14 @@ add_drop: ADD_P { $$ = +1; }
10821082
*****************************************************************************/
10831083

10841084
DropGroupStmt:
1085-
DROP GROUP_P name_list
1085+
DROP GROUP_P role_list
10861086
{
10871087
DropRoleStmt *n = makeNode(DropRoleStmt);
10881088
n->missing_ok = FALSE;
10891089
n->roles = $3;
10901090
$$ = (Node *)n;
10911091
}
1092-
| DROP GROUP_P IF_P EXISTS name_list
1092+
| DROP GROUP_P IF_P EXISTS role_list
10931093
{
10941094
DropRoleStmt *n = makeNode(DropRoleStmt);
10951095
n->missing_ok = TRUE;
@@ -3997,8 +3997,8 @@ DropOpFamilyStmt:
39973997
*
39983998
*****************************************************************************/
39993999
DropOwnedStmt:
4000-
DROP OWNED BY name_list opt_drop_behavior
4001-
{
4000+
DROP OWNED BY role_list opt_drop_behavior
4001+
{
40024002
DropOwnedStmt *n = makeNode(DropOwnedStmt);
40034003
n->roles = $4;
40044004
n->behavior = $5;
@@ -4007,7 +4007,7 @@ DropOwnedStmt:
40074007
;
40084008

40094009
ReassignOwnedStmt:
4010-
REASSIGN OWNED BY name_list TO name
4010+
REASSIGN OWNED BY role_list TO name
40114011
{
40124012
ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
40134013
n->roles = $4;
@@ -4748,7 +4748,7 @@ function_with_argtypes:
47484748
*****************************************************************************/
47494749

47504750
GrantRoleStmt:
4751-
GRANT privilege_list TO name_list opt_grant_admin_option opt_granted_by
4751+
GRANT privilege_list TO role_list opt_grant_admin_option opt_granted_by
47524752
{
47534753
GrantRoleStmt *n = makeNode(GrantRoleStmt);
47544754
n->is_grant = true;
@@ -4761,7 +4761,7 @@ GrantRoleStmt:
47614761
;
47624762

47634763
RevokeRoleStmt:
4764-
REVOKE privilege_list FROM name_list opt_granted_by opt_drop_behavior
4764+
REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
47654765
{
47664766
GrantRoleStmt *n = makeNode(GrantRoleStmt);
47674767
n->is_grant = false;
@@ -4771,7 +4771,7 @@ RevokeRoleStmt:
47714771
n->behavior = $6;
47724772
$$ = (Node*)n;
47734773
}
4774-
| REVOKE ADMIN OPTION FOR privilege_list FROM name_list opt_granted_by opt_drop_behavior
4774+
| REVOKE ADMIN OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
47754775
{
47764776
GrantRoleStmt *n = makeNode(GrantRoleStmt);
47774777
n->is_grant = false;
@@ -4817,11 +4817,11 @@ DefACLOption:
48174817
{
48184818
$$ = makeDefElem("schemas", (Node *)$3);
48194819
}
4820-
| FOR ROLE name_list
4820+
| FOR ROLE role_list
48214821
{
48224822
$$ = makeDefElem("roles", (Node *)$3);
48234823
}
4824-
| FOR USER name_list
4824+
| FOR USER role_list
48254825
{
48264826
$$ = makeDefElem("roles", (Node *)$3);
48274827
}
@@ -10778,6 +10778,12 @@ Iconst: ICONST { $$ = $1; };
1077810778
Sconst: SCONST { $$ = $1; };
1077910779
RoleId: NonReservedWord { $$ = $1; };
1078010780

10781+
role_list: RoleId
10782+
{ $$ = list_make1(makeString($1)); }
10783+
| role_list ',' RoleId
10784+
{ $$ = lappend($1, makeString($3)); }
10785+
;
10786+
1078110787
SignedIconst: Iconst { $$ = $1; }
1078210788
| '+' Iconst { $$ = + $2; }
1078310789
| '-' Iconst { $$ = - $2; }

0 commit comments

Comments
 (0)