Redshift でデータシェアリングで共有されたテーブルに対して、Consumer 側から View を作成した場合、Producer 側のテーブルを Drop できるか。
検証手順
- [Producer側]スキーマとテーブルを作成する
CREATE SCHEMA IF NOT EXISTS share_schema; CREATE TABLE IF NOT EXISTS share_schema.share_table( id NUMERIC(18,0), name CHARACTER VARYING(10) ); INSERT INTO share_schema.share_table VALUES(1, 'chicken'); INSERT INTO share_schema.share_table VALUES(2, 'pook'); INSERT INTO share_schema.share_table VALUES(3, 'beef');
- [Producer側]データシェアリングを設定
CREATE DATASHARE share_db1; ALTER DATASHARE share_db1 SET publicaccessible = TRUE; ALTER DATASHARE share_db1 ADD SCHEMA share_schema;
- [Producer側]ネームスペースを確認する
select current_namespace; current_namespace -------------------------------------- 248c1dda-67e3-4552-b795-3982dfeca8ec (1 row)
- Producer 側で実行
GRANT USAGE ON DATASHARE share_db1 TO NAMESPACE '248c1dda-67e3-4552-b795-3982dfeca8ec';
Consumer 側のクラスター
SELECT producer_namespace FROM svv_datashares where share_name = 'share_db1'; producer_namespace ------------------------------------------------------------------ 8fe81794-e567-46f8-9d0d-3ddd862b7299 (1 row) -- 上のクエリで取得した "producer_namespace" を以下のクエリの <Name space> に指定する CREATE DATABASE share_db1 FROM DATASHARE share_db1 OF NAMESPACE '8fe81794-e567-46f8-9d0d-3ddd862b7299'; grant usage on database share_db1 to group admin_group; DESC DATASHARE central_db of ACCOUNT '1234567890123' NAMESPACE '8fe81794-e567-46f8-9d0d-3ddd862b7299'; producer_account | producer_namespace | share_type | share_name | object_type | object_name | include_new ------------------+--------------------------------------+------------+------------+-------------+--------------------------+------------- 1234567890123 | 8fe81794-e567-46f8-9d0d-3ddd862b7299 | INBOUND | central_db | schema | share_schema | 1234567890123 | 8fe81794-e567-46f8-9d0d-3ddd862b7299 | INBOUND | central_db | table | share_schema.share_table | (2 rows) GRANT USAGE ON DATABASE central_db TO awsuser; grant usage on schema central_db.share_schema to public; GRANT SELECT ON ALL TABLES IN SCHEMA central_db.share_schema TO public; select * from test_share.share_schema.share_table; id | name ----+--------- 2 | pook 3 | beef 1 | chicken 4 | ram (4 rows) CREATE VIEW datashare_view AS SELECT * FROM test_share.share_schema.share_table; ERROR: External tables are not supported in views HINT: Please use late binding view and add 'with no schema binding' at the query end. CREATE VIEW datashare_view AS SELECT * FROM test_share.share_schema.share_table with no schema binding; dev=# select * from datashare_view; id | name ----+--------- 2 | pook 3 | beef 1 | chicken 4 | ram (4 rows)