4 |
(3 rows)
+ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
+SELECT COUNT(*) FROM pg_class WHERE relnamespace =
+ (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+ count
+-------
+ 0
+(1 row)
+
-- test IF NOT EXISTS cases
-CREATE SCHEMA test_schema_1; -- fail, already exists
-ERROR: schema "test_schema_1" already exists
-CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice
-NOTICE: schema "test_schema_1" already exists, skipping
-CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
+CREATE SCHEMA test_schema_renamed; -- fail, already exists
+ERROR: schema "test_schema_renamed" already exists
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
+NOTICE: schema "test_schema_renamed" already exists, skipping
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
CREATE TABLE abc (
a serial,
b int UNIQUE
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
LINE 2: CREATE TABLE abc (
^
-DROP SCHEMA test_schema_1 CASCADE;
+DROP SCHEMA test_schema_renamed CASCADE;
NOTICE: drop cascades to 2 other objects
-DETAIL: drop cascades to table test_schema_1.abc
-drop cascades to view test_schema_1.abc_view
+DETAIL: drop cascades to table test_schema_renamed.abc
+drop cascades to view test_schema_renamed.abc_view
-- verify that the objects were dropped
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
- (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+ (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
count
-------
0
SET client_min_messages TO 'warning';
DROP SCHEMA testns CASCADE;
RESET client_min_messages;
+-- Change owner of the schema & and rename of new schema owner
+\c -
+CREATE ROLE schemauser1 superuser login;
+CREATE ROLE schemauser2 superuser login;
+SET SESSION ROLE schemauser1;
+CREATE SCHEMA testns;
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+ nspname | rolname
+---------+-------------
+ testns | schemauser1
+(1 row)
+
+ALTER SCHEMA testns OWNER TO schemauser2;
+ALTER ROLE schemauser2 RENAME TO schemauser_renamed;
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+ nspname | rolname
+---------+--------------------
+ testns | schemauser_renamed
+(1 row)
+
+set session role schemauser_renamed;
+SET client_min_messages TO 'warning';
+DROP SCHEMA testns CASCADE;
+RESET client_min_messages;
+-- clean up
+\c -
+DROP ROLE schemauser1;
+DROP ROLE schemauser_renamed;
-- test that dependent privileges are revoked (or not) properly
\c -
set session role regressuser1;
SELECT * FROM test_schema_1.abc;
SELECT * FROM test_schema_1.abc_view;
+ALTER SCHEMA test_schema_1 RENAME TO test_schema_renamed;
+SELECT COUNT(*) FROM pg_class WHERE relnamespace =
+ (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+
-- test IF NOT EXISTS cases
-CREATE SCHEMA test_schema_1; -- fail, already exists
-CREATE SCHEMA IF NOT EXISTS test_schema_1; -- ok with notice
-CREATE SCHEMA IF NOT EXISTS test_schema_1 -- fail, disallowed
+CREATE SCHEMA test_schema_renamed; -- fail, already exists
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed; -- ok with notice
+CREATE SCHEMA IF NOT EXISTS test_schema_renamed -- fail, disallowed
CREATE TABLE abc (
a serial,
b int UNIQUE
);
-DROP SCHEMA test_schema_1 CASCADE;
+DROP SCHEMA test_schema_renamed CASCADE;
-- verify that the objects were dropped
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
- (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
+ (SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
RESET client_min_messages;
+-- Change owner of the schema & and rename of new schema owner
+\c -
+
+CREATE ROLE schemauser1 superuser login;
+CREATE ROLE schemauser2 superuser login;
+
+SET SESSION ROLE schemauser1;
+CREATE SCHEMA testns;
+
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+
+ALTER SCHEMA testns OWNER TO schemauser2;
+ALTER ROLE schemauser2 RENAME TO schemauser_renamed;
+SELECT nspname, rolname FROM pg_namespace, pg_roles WHERE pg_namespace.nspname = 'testns' AND pg_namespace.nspowner = pg_roles.oid;
+
+set session role schemauser_renamed;
+SET client_min_messages TO 'warning';
+DROP SCHEMA testns CASCADE;
+RESET client_min_messages;
+
+-- clean up
+\c -
+
+DROP ROLE schemauser1;
+DROP ROLE schemauser_renamed;
+
+
-- test that dependent privileges are revoked (or not) properly
\c -