Support the the usage of "ALTER TYPE name OWNER TO { CURRENT_USER | SESSION_USER }"
This commit is contained in:
@ -510,7 +510,7 @@ static void ParseUpdateMultiSet(List *set_target_list, SelectStmt *stmt, core_yy
|
||||
|
||||
%type <ival> Iconst SignedIconst
|
||||
%type <str> Sconst comment_text notify_payload
|
||||
%type <str> RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst
|
||||
%type <str> RoleId TypeOwner opt_granted_by opt_boolean_or_string ColId_or_Sconst
|
||||
%type <list> var_list
|
||||
%type <str> ColId ColLabel var_name type_function_name param_name
|
||||
%type <node> var_value zone_value
|
||||
@ -11013,7 +11013,7 @@ AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
|
||||
n->newowner = $6;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| ALTER TYPE_P any_name OWNER TO RoleId
|
||||
| ALTER TYPE_P any_name OWNER TO TypeOwner
|
||||
{
|
||||
AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
|
||||
n->objectType = OBJECT_TYPE;
|
||||
@ -11079,6 +11079,11 @@ AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
|
||||
}
|
||||
;
|
||||
|
||||
TypeOwner:
|
||||
RoleId { $$ = $1; }
|
||||
| CURRENT_USER { $$ = pstrdup($1); }
|
||||
| SESSION_USER { $$ = pstrdup($1); }
|
||||
;
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
|
||||
@ -465,7 +465,18 @@ Oid AlterObjectNamespace(Relation rel, int oidCacheId, int nameCacheId, Oid obji
|
||||
*/
|
||||
void ExecAlterOwnerStmt(AlterOwnerStmt* stmt)
|
||||
{
|
||||
Oid newowner = get_role_oid(stmt->newowner, false);
|
||||
const char* newOwnerName = stmt->newowner;
|
||||
Oid newowner;
|
||||
if (strcmp(newOwnerName, "current_user") == 0) {
|
||||
/* CURRENT_USER */
|
||||
newowner = GetUserId();
|
||||
} else if (strcmp(newOwnerName, "session_user") == 0) {
|
||||
/* SESSION_USER */
|
||||
newowner = GetSessionUserId();
|
||||
} else {
|
||||
/* Normal User */
|
||||
newowner = get_role_oid(newOwnerName, false);
|
||||
}
|
||||
|
||||
switch (stmt->objectType) {
|
||||
case OBJECT_AGGREGATE:
|
||||
|
||||
@ -148,3 +148,11 @@ loc_id i_int2 := (19,1)
|
||||
dept_rec DeptRecTyp;
|
||||
BEGIN
|
||||
END
|
||||
|
||||
CREATE ROLE test_role WITH PASSWORD 'Huawei@123';
|
||||
CREATE TYPE test_type as (id int);
|
||||
ALTER TYPE test_type OWNER TO test_role;
|
||||
ALTER TYPE test_type OWNER TO CURRENT_USER;
|
||||
ALTER TYPE test_type OWNER TO SESSION_USER;
|
||||
DROP TYPE test_type;
|
||||
DROP ROLE test_role;
|
||||
|
||||
@ -130,3 +130,10 @@ BEGIN
|
||||
END;
|
||||
/
|
||||
|
||||
CREATE ROLE test_role WITH PASSWORD 'Huawei@123';
|
||||
CREATE TYPE test_type as (id int);
|
||||
ALTER TYPE test_type OWNER TO test_role;
|
||||
ALTER TYPE test_type OWNER TO CURRENT_USER;
|
||||
ALTER TYPE test_type OWNER TO SESSION_USER;
|
||||
DROP TYPE test_type;
|
||||
DROP ROLE test_role;
|
||||
|
||||
Reference in New Issue
Block a user