2 -- Regression tests for schemas (namespaces)
4 -- set the whitespace-only search_path to test that the
5 -- GUC list syntax is preserved during a schema creation
6 SELECT pg_catalog.set_config('search_path', ' ', false);
12 CREATE SCHEMA test_ns_schema_1
13 CREATE UNIQUE INDEX abc_a_idx ON abc (a)
14 CREATE VIEW abc_view AS
15 SELECT a+1 AS a, b+1 AS b FROM abc
20 -- verify that the correct search_path restored on abort
21 SET search_path to public;
23 SET search_path to public, test_ns_schema_1;
24 CREATE SCHEMA test_ns_schema_2
25 CREATE VIEW abc_view AS SELECT c FROM abc;
26 ERROR: column "c" does not exist
27 LINE 2: CREATE VIEW abc_view AS SELECT c FROM abc;
36 -- verify that the correct search_path preserved
37 -- after creating the schema and on commit
39 SET search_path to public, test_ns_schema_1;
40 CREATE SCHEMA test_ns_schema_2
41 CREATE VIEW abc_view AS SELECT a FROM abc;
44 --------------------------
45 public, test_ns_schema_1
51 --------------------------
52 public, test_ns_schema_1
55 DROP SCHEMA test_ns_schema_2 CASCADE;
56 NOTICE: drop cascades to view test_ns_schema_2.abc_view
57 -- verify that the objects were created
58 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
59 (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1');
65 INSERT INTO test_ns_schema_1.abc DEFAULT VALUES;
66 INSERT INTO test_ns_schema_1.abc DEFAULT VALUES;
67 INSERT INTO test_ns_schema_1.abc DEFAULT VALUES;
68 SELECT * FROM test_ns_schema_1.abc;
76 SELECT * FROM test_ns_schema_1.abc_view;
84 ALTER SCHEMA test_ns_schema_1 RENAME TO test_ns_schema_renamed;
85 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
86 (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_1');
92 -- test IF NOT EXISTS cases
93 CREATE SCHEMA test_ns_schema_renamed; -- fail, already exists
94 ERROR: schema "test_ns_schema_renamed" already exists
95 CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed; -- ok with notice
96 NOTICE: schema "test_ns_schema_renamed" already exists, skipping
97 CREATE SCHEMA IF NOT EXISTS test_ns_schema_renamed -- fail, disallowed
102 ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
103 LINE 2: CREATE TABLE abc (
105 DROP SCHEMA test_ns_schema_renamed CASCADE;
106 NOTICE: drop cascades to 2 other objects
107 DETAIL: drop cascades to table test_ns_schema_renamed.abc
108 drop cascades to view test_ns_schema_renamed.abc_view
109 -- verify that the objects were dropped
110 SELECT COUNT(*) FROM pg_class WHERE relnamespace =
111 (SELECT oid FROM pg_namespace WHERE nspname = 'test_ns_schema_renamed');