2 -- Regression tests for schemas (namespaces)
4 CREATE SCHEMA test_ns_schema_1
5 CREATE UNIQUE INDEX abc_a_idx ON abc (a)
6 CREATE VIEW abc_view AS
7 SELECT a+1 AS a, b+1 AS b FROM abc
12 -- verify that the objects were created
13 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
14 (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1');
20 INSERT INTO test_ns_schema_1.abc DEFAULT VALUES;
21 INSERT INTO test_ns_schema_1.abc DEFAULT VALUES;
22 INSERT INTO test_ns_schema_1.abc DEFAULT VALUES;
23 SELECT * FROM test_ns_schema_1.abc;
31 SELECT * FROM test_ns_schema_1.abc_view;
39 ALTER SCHEMA test_ns_schema_1 RENAME TO test_ns_schema_renamed;
40 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
41 (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1');
47 -- test IF NOT EXISTS cases
48 CREATE SCHEMA test_ns_schema_renamed; -- fail, already exists
49 ERROR: schema "test_ns_schema_renamed" already exists
50 CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed; -- ok with notice
51 NOTICE: schema "test_ns_schema_renamed" already exists, skipping
52 CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed
57 ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
58 LINE 2: CREATE TABLE abc (
60 DROP SCHEMA test_ns_schema_renamed CASCADE;
61 NOTICE: drop cascades to 2 other objects
62 DETAIL: drop cascades to table test_ns_schema_renamed.abc
63 drop cascades to view test_ns_schema_renamed.abc_view
64 -- verify that the objects were dropped
65 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
66 (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_renamed');