Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

HAWQ-1556. enable ALTER SCHEMA RENAME/OWNER #1315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/backend/commands/alter.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ ExecRenameStmt(RenameStmt *stmt)
break;

case OBJECT_SCHEMA:
if (!gp_called_by_pgdump)
{
ereport(ERROR,
(errcode(ERRCODE_CDB_FEATURE_NOT_YET), errmsg("Cannot support rename schema statement yet") ));
}
RenameSchema(stmt->subname, stmt->newname);
break;

Expand Down Expand Up @@ -304,9 +299,6 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
break;

case OBJECT_SCHEMA:
if (!gp_called_by_pgdump)
ereport(ERROR,
(errcode(ERRCODE_CDB_FEATURE_NOT_YET), errmsg("Cannot support alter schema owner statement yet") ));
AlterSchemaOwner(strVal(linitial(stmt->object)), newowner);
break;

Expand Down
28 changes: 25 additions & 3 deletions src/test/feature/catalog/ans/alter-owner.ans
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,36 @@ select
alter database u1 owner to u1;
psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:24: ERROR: Cannot support alter database owner statement yet
alter schema u1 owner to u1;
psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:25: ERROR: Cannot support alter schema owner statement yet
reset session authorization;
ALTER SCHEMA
alter schema u1 rename to u2;
ALTER SCHEMA
-- test permission
create role u2;
psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:29: NOTICE: resource queue required -- using default resource queue "pg_default"
CREATE ROLE
ALTER SCHEMA pg_toast OWNER to u2; -- system schema
psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:30: ERROR: permission denied to ALTER SCHEMA "pg_toast"
DETAIL: Schema pg_toast is reserved for system use.
GRANT ALL ON SCHEMA u2 to u2;
GRANT
RESET SESSION AUTHORIZATION;
RESET
SET SESSION AUTHORIZATION u2;
SET
CREATE TABLE u2.grant_test(a int) DISTRIBUTED BY (a);
CREATE TABLE
ALTER SCHEMA u2 RENAME to myschema; -- not the schema owner
psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:35: ERROR: must be owner of schema u2
RESET SESSION AUTHORIZATION;
RESET
drop database u1;
DROP DATABASE
drop schema u1;
drop schema u2 CASCADE;
psql:/tmp/TestAlterOwner_TestAlterOwnerAll.sql:39: NOTICE: drop cascades to append only table u2.grant_test
DROP SCHEMA
drop role u1;
DROP ROLE
drop role u2;
DROP ROLE
drop role super;
DROP ROLE
17 changes: 14 additions & 3 deletions src/test/feature/catalog/sql/alter-owner.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ select

alter database u1 owner to u1;
alter schema u1 owner to u1;
alter schema u1 rename to u2;

reset session authorization;
-- test permission
create role u2;
ALTER SCHEMA pg_toast OWNER to u2; -- system schema
GRANT ALL ON SCHEMA u2 to u2;
RESET SESSION AUTHORIZATION;
SET SESSION AUTHORIZATION u2;
CREATE TABLE u2.grant_test(a int) DISTRIBUTED BY (a);
ALTER SCHEMA u2 RENAME to myschema; -- not the schema owner

RESET SESSION AUTHORIZATION;
drop database u1;
drop schema u1;
drop schema u2 CASCADE;
drop role u1;
drop role super;
drop role u2;
drop role super;