diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 5a563d1df..b21deecbe 100755 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -510,7 +510,7 @@ static void ParseUpdateMultiSet(List *set_target_list, SelectStmt *stmt, core_yy %type Iconst SignedIconst %type Sconst comment_text notify_payload -%type RoleId opt_granted_by opt_boolean_or_string ColId_or_Sconst +%type RoleId TypeOwner opt_granted_by opt_boolean_or_string ColId_or_Sconst %type var_list %type ColId ColLabel var_name type_function_name param_name %type 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); } + ; /***************************************************************************** * diff --git a/src/gausskernel/optimizer/commands/alter.cpp b/src/gausskernel/optimizer/commands/alter.cpp index a462f59be..54eef399e 100755 --- a/src/gausskernel/optimizer/commands/alter.cpp +++ b/src/gausskernel/optimizer/commands/alter.cpp @@ -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: diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out index 00a1747ca..eebab5287 100644 --- a/src/test/regress/expected/create_type.out +++ b/src/test/regress/expected/create_type.out @@ -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; diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql index f1f242ec5..9013db37e 100644 --- a/src/test/regress/sql/create_type.sql +++ b/src/test/regress/sql/create_type.sql @@ -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;