2004-01-11 05:58:17 +01:00
|
|
|
--
|
|
|
|
-- Regression tests for schemas (namespaces)
|
|
|
|
--
|
|
|
|
CREATE SCHEMA test_schema_1
|
|
|
|
CREATE UNIQUE INDEX abc_a_idx ON abc (a)
|
|
|
|
CREATE VIEW abc_view AS
|
|
|
|
SELECT a+1 AS a, b+1 AS b FROM abc
|
|
|
|
CREATE TABLE abc (
|
|
|
|
a serial,
|
|
|
|
b int UNIQUE
|
|
|
|
);
|
|
|
|
-- verify that the objects were created
|
|
|
|
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
|
|
|
|
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_1');
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
5
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
INSERT INTO test_schema_1.abc DEFAULT VALUES;
|
|
|
|
INSERT INTO test_schema_1.abc DEFAULT VALUES;
|
|
|
|
INSERT INTO test_schema_1.abc DEFAULT VALUES;
|
|
|
|
SELECT * FROM test_schema_1.abc;
|
|
|
|
a | b
|
|
|
|
---+---
|
|
|
|
1 |
|
|
|
|
2 |
|
|
|
|
3 |
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM test_schema_1.abc_view;
|
|
|
|
a | b
|
|
|
|
---+---
|
|
|
|
2 |
|
|
|
|
3 |
|
|
|
|
4 |
|
|
|
|
(3 rows)
|
|
|
|
|
2013-12-11 21:45:15 +01:00
|
|
|
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)
|
|
|
|
|
2012-10-04 01:47:11 +02:00
|
|
|
-- test IF NOT EXISTS cases
|
2013-12-11 21:45:15 +01:00
|
|
|
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
|
2012-10-04 01:47:11 +02:00
|
|
|
CREATE TABLE abc (
|
|
|
|
a serial,
|
|
|
|
b int UNIQUE
|
|
|
|
);
|
|
|
|
ERROR: CREATE SCHEMA IF NOT EXISTS cannot include schema elements
|
2012-10-04 23:14:59 +02:00
|
|
|
LINE 2: CREATE TABLE abc (
|
|
|
|
^
|
2013-12-11 21:45:15 +01:00
|
|
|
DROP SCHEMA test_schema_renamed CASCADE;
|
2008-06-11 23:53:49 +02:00
|
|
|
NOTICE: drop cascades to 2 other objects
|
2013-12-11 21:45:15 +01:00
|
|
|
DETAIL: drop cascades to table test_schema_renamed.abc
|
|
|
|
drop cascades to view test_schema_renamed.abc_view
|
2004-01-11 05:58:17 +01:00
|
|
|
-- verify that the objects were dropped
|
|
|
|
SELECT COUNT(*) FROM pg_class WHERE relnamespace =
|
2013-12-11 21:45:15 +01:00
|
|
|
(SELECT oid FROM pg_namespace WHERE nspname = 'test_schema_renamed');
|
2004-01-11 05:58:17 +01:00
|
|
|
count
|
|
|
|
-------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|