同じ名前の複数のスキーマに存在するテーブルに1つのビュー(または変更なしで使用される各スキーマのビュー)を作成しようとしています
create schema company_1;
create schema company_2;
...
CREATE TABLE company_1.orders
(
id serial NOT NULL,
amount real,
paid real,
CONSTRAINT orders_pkey PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
CREATE TABLE company_2.orders
(
id serial NOT NULL,
amount real,
paid real,
CONSTRAINT orders_pkey PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
....
すべてのビューにスキーマを指定したり、現在のスキーマを指定したりせずに、テーブルの順序でビューを作成する正しい方法は何ですか?
私が必要とし、入手できなかったのはどちらかです
CREATE OR REPLACE VIEW
public.full_orders AS
SELECT id, amount FROM orders;
また
CREATE OR REPLACE VIEW
company_1.full_orders AS
-- company_2.full_orders AS
-- company_n.full_orders AS
SELECT id, amount FROM current_schema.orders;
postgresql9.2.2の使用
編集:私が行った方法:
CREATE VIEW company_1.full_orders AS
SELECT id, amount FROM company_1.orders;
ここで説明するスキーマコピーでは、これを実行します
FOR src_table IN
SELECT table_name
FROM information_schema.TABLES
WHERE table_schema = source_schema AND table_type = 'VIEW'
LOOP
SELECT view_definition
FROM information_schema.views
WHERE table_name = src_table AND table_schema = source_schema INTO q;
trg_table := target_schema||'.'||src_table;
EXECUTE 'CREATE VIEW ' || trg_table || ' AS '||replace(q, source_schema, target_schema);
END LOOP;
まだより良い解決策を探しています...