Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b374481

Browse files
committed
Further unify ROLE and USER command grammar rules
ALTER USER ... SET did not support all the syntax variants of ALTER ROLE ... SET. Fix that, and to avoid further deviations of this kind, unify many the grammar rules for ROLE/USER/GROUP commands. Reported-by: Pavel Golub <pavel@microolap.com>
1 parent 3eb9a5e commit b374481

File tree

3 files changed

+43
-80
lines changed

3 files changed

+43
-80
lines changed

doc/src/sgml/ref/alter_user.sgml

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> [ WIT
3838

3939
ALTER USER <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable>new_name</replaceable>
4040

41-
ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
42-
ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
43-
ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> RESET <replaceable>configuration_parameter</replaceable>
44-
ALTER USER <replaceable class="PARAMETER">role_specification</replaceable> RESET ALL
41+
ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> { TO | = } { <replaceable>value</replaceable> | DEFAULT }
42+
ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] SET <replaceable>configuration_parameter</replaceable> FROM CURRENT
43+
ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET <replaceable>configuration_parameter</replaceable>
44+
ALTER USER { <replaceable class="PARAMETER">role_specification</replaceable> | ALL } [ IN DATABASE <replaceable class="PARAMETER">database_name</replaceable> ] RESET ALL
4545

4646
<phrase>where <replaceable class="PARAMETER">role_specification</replaceable> can be:</phrase>
4747

src/backend/parser/gram.y

+37-68
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
250250
AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
251251
AlterOperatorStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
252252
AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
253-
AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
253+
AlterCompositeTypeStmt AlterUserMappingStmt
254254
AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt
255255
AlterDefaultPrivilegesStmt DefACLAction
256256
AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
@@ -262,9 +262,9 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
262262
CreateAssertStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
263263
CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
264264
CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
265-
DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
265+
DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
266266
DropAssertStmt DropCastStmt DropRoleStmt
267-
DropUserStmt DropdbStmt DropTableSpaceStmt
267+
DropdbStmt DropTableSpaceStmt
268268
DropTransformStmt
269269
DropUserMappingStmt ExplainStmt FetchStmt
270270
GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
@@ -841,8 +841,6 @@ stmt :
841841
| AlterTSConfigurationStmt
842842
| AlterTSDictionaryStmt
843843
| AlterUserMappingStmt
844-
| AlterUserSetStmt
845-
| AlterUserStmt
846844
| AnalyzeStmt
847845
| CheckPointStmt
848846
| ClosePortalStmt
@@ -890,7 +888,6 @@ stmt :
890888
| DoStmt
891889
| DropAssertStmt
892890
| DropCastStmt
893-
| DropGroupStmt
894891
| DropOpClassStmt
895892
| DropOpFamilyStmt
896893
| DropOwnedStmt
@@ -900,7 +897,6 @@ stmt :
900897
| DropTableSpaceStmt
901898
| DropTransformStmt
902899
| DropRoleStmt
903-
| DropUserStmt
904900
| DropUserMappingStmt
905901
| DropdbStmt
906902
| ExecuteStmt
@@ -1130,6 +1126,14 @@ AlterRoleStmt:
11301126
n->options = $5;
11311127
$$ = (Node *)n;
11321128
}
1129+
| ALTER USER RoleSpec opt_with AlterOptRoleList
1130+
{
1131+
AlterRoleStmt *n = makeNode(AlterRoleStmt);
1132+
n->role = $3;
1133+
n->action = +1; /* add, if there are members */
1134+
n->options = $5;
1135+
$$ = (Node *)n;
1136+
}
11331137
;
11341138

11351139
opt_in_database:
@@ -1154,37 +1158,23 @@ AlterRoleSetStmt:
11541158
n->setstmt = $5;
11551159
$$ = (Node *)n;
11561160
}
1157-
;
1158-
1159-
1160-
/*****************************************************************************
1161-
*
1162-
* Alter a postgresql DBMS user
1163-
*
1164-
*****************************************************************************/
1165-
1166-
AlterUserStmt:
1167-
ALTER USER RoleSpec opt_with AlterOptRoleList
1168-
{
1169-
AlterRoleStmt *n = makeNode(AlterRoleStmt);
1161+
| ALTER USER RoleSpec opt_in_database SetResetClause
1162+
{
1163+
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
11701164
n->role = $3;
1171-
n->action = +1; /* add, if there are members */
1172-
n->options = $5;
1165+
n->database = $4;
1166+
n->setstmt = $5;
11731167
$$ = (Node *)n;
1174-
}
1175-
;
1176-
1177-
1178-
AlterUserSetStmt:
1179-
ALTER USER RoleSpec SetResetClause
1168+
}
1169+
| ALTER USER ALL opt_in_database SetResetClause
11801170
{
11811171
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
1182-
n->role = $3;
1183-
n->database = NULL;
1184-
n->setstmt = $4;
1172+
n->role = NULL;
1173+
n->database = $4;
1174+
n->setstmt = $5;
11851175
$$ = (Node *)n;
11861176
}
1187-
;
1177+
;
11881178

11891179

11901180
/*****************************************************************************
@@ -1211,17 +1201,7 @@ DropRoleStmt:
12111201
n->roles = $5;
12121202
$$ = (Node *)n;
12131203
}
1214-
;
1215-
1216-
/*****************************************************************************
1217-
*
1218-
* Drop a postgresql DBMS user
1219-
*
1220-
* XXX As with DROP ROLE, no CASCADE/RESTRICT here.
1221-
*****************************************************************************/
1222-
1223-
DropUserStmt:
1224-
DROP USER role_list
1204+
| DROP USER role_list
12251205
{
12261206
DropRoleStmt *n = makeNode(DropRoleStmt);
12271207
n->missing_ok = FALSE;
@@ -1235,6 +1215,20 @@ DropUserStmt:
12351215
n->missing_ok = TRUE;
12361216
$$ = (Node *)n;
12371217
}
1218+
| DROP GROUP_P role_list
1219+
{
1220+
DropRoleStmt *n = makeNode(DropRoleStmt);
1221+
n->missing_ok = FALSE;
1222+
n->roles = $3;
1223+
$$ = (Node *)n;
1224+
}
1225+
| DROP GROUP_P IF_P EXISTS role_list
1226+
{
1227+
DropRoleStmt *n = makeNode(DropRoleStmt);
1228+
n->missing_ok = TRUE;
1229+
n->roles = $5;
1230+
$$ = (Node *)n;
1231+
}
12381232
;
12391233

12401234

@@ -1279,31 +1273,6 @@ add_drop: ADD_P { $$ = +1; }
12791273
;
12801274

12811275

1282-
/*****************************************************************************
1283-
*
1284-
* Drop a postgresql group
1285-
*
1286-
* XXX As with DROP ROLE, no CASCADE/RESTRICT here.
1287-
*****************************************************************************/
1288-
1289-
DropGroupStmt:
1290-
DROP GROUP_P role_list
1291-
{
1292-
DropRoleStmt *n = makeNode(DropRoleStmt);
1293-
n->missing_ok = FALSE;
1294-
n->roles = $3;
1295-
$$ = (Node *)n;
1296-
}
1297-
| DROP GROUP_P IF_P EXISTS role_list
1298-
{
1299-
DropRoleStmt *n = makeNode(DropRoleStmt);
1300-
n->missing_ok = TRUE;
1301-
n->roles = $5;
1302-
$$ = (Node *)n;
1303-
}
1304-
;
1305-
1306-
13071276
/*****************************************************************************
13081277
*
13091278
* Manipulate a schema

src/test/regress/expected/rolenames.out

+2-8
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ ERROR: syntax error at or near "CURRENT_ROLE"
310310
LINE 1: ALTER USER CURRENT_ROLE WITH LOGIN;
311311
^
312312
ALTER USER ALL WITH REPLICATION; -- error
313-
ERROR: syntax error at or near "ALL"
313+
ERROR: syntax error at or near "WITH"
314314
LINE 1: ALTER USER ALL WITH REPLICATION;
315-
^
315+
^
316316
ALTER USER SESSION_ROLE WITH NOREPLICATION; -- error
317317
ERROR: role "session_role" does not exist
318318
ALTER USER PUBLIC WITH NOREPLICATION; -- error
@@ -392,9 +392,6 @@ ALTER USER SESSION_USER SET application_name to 'BAR';
392392
ALTER USER "current_user" SET application_name to 'FOOFOO';
393393
ALTER USER "Public" SET application_name to 'BARBAR';
394394
ALTER USER ALL SET application_name to 'SLAP';
395-
ERROR: syntax error at or near "ALL"
396-
LINE 1: ALTER USER ALL SET application_name to 'SLAP';
397-
^
398395
SELECT * FROM chksetconfig();
399396
db | role | rolkeyword | setconfig
400397
-----+------------------+--------------+---------------------------
@@ -419,9 +416,6 @@ ALTER USER SESSION_USER RESET application_name;
419416
ALTER USER "current_user" RESET application_name;
420417
ALTER USER "Public" RESET application_name;
421418
ALTER USER ALL RESET application_name;
422-
ERROR: syntax error at or near "ALL"
423-
LINE 1: ALTER USER ALL RESET application_name;
424-
^
425419
SELECT * FROM chksetconfig();
426420
db | role | rolkeyword | setconfig
427421
----+------+------------+-----------

0 commit comments

Comments
 (0)