2014-01-17 22 views
1

使用postgres_fdw,我需要在指定的模式中創建外部表以防止名稱衝突。爲了找出我遇到的問題,我在同一個集羣上設置了兩個測試postgres數據庫,分別是import_test和export_test。 Export_test有一個表,foreign_schema.aa。在服務器import_test,做其他的外籍家政工人的先決條件後,我跑:爲什麼postgres_fdw雙重資格模式?

CREATE FOREIGN TABLE local_schema.aa(
    id serial NOT NULL, 
    dat text 
) SERVER export_server OPTIONS (table_name 'foreign_schema.aa'); 

然後:

SELECT * FROM local_schema.aa; 

當我這樣做,我得到:

ERROR: relation "local_schema.foreign_schema.aa" does not exist 
CONTEXT: Remote SQL command: SELECT id, dat FROM local_schema."foreign_schema.aa" 

如果我不」 t做任何模式鑑定,如:

CREATE FOREIGN TABLE aa(
    id serial NOT NULL, 
    dat text 
) SERVER export_server OPTIONS (table_name 'aa'); 

並將aa表移動到公共架構,選擇工作得很好。

如果命令「SELECT id,dat FROM local_schema。」foreign_schema.aa「字面上在遠程服務器上運行,這很明顯爲什麼它不起作用:local_schema。」foreign_schema.aa「確實不存在因爲某些原因,postgres_fdw似乎預先給出了table_name的名稱和外部表的模式

我需要在select查詢中指定模式,因爲如果我不這樣做沒有看到外表,通過設置搜索路徑來實現模式限定也沒有幫助,

有什麼我做錯了嗎?如果沒有,是否有解決方法將讓我模式合格的外國表?

編輯:每@Craig林格的建議,這裏是自包含的psql輸入:

CREATE USER test_user SUPERUSER PASSWORD 'password'; 
SET ROLE test_user; 
CREATE DATABASE import; 
CREATE DATABASE export; 
\c export test_user 
CREATE SCHEMA export_schema; 
CREATE TABLE export_schema.aa (
    id serial PRIMARY KEY, 
    dat text 
); 
\c import test_user 
CREATE EXTENSION postgres_fdw; 
CREATE SERVER export_server 
    FOREIGN DATA WRAPPER postgres_fdw 
    OPTIONS (host 'localhost', dbname 'export', port '5432'); 
CREATE USER MAPPING FOR test_user 
    SERVER export_server 
    OPTIONS (user 'test_user', password 'password'); 
CREATE SCHEMA import_schema;   
CREATE FOREIGN TABLE import_schema.aa(
    id serial NOT NULL, 
    dat text 
) SERVER export_server OPTIONS (table_name 'export_schema.aa'); 
SELECT * FROM import_schema.aa; 

其中產量輸出:

ERROR: relation "import_schema.export_schema.aa" does not exist 
CONTEXT: Remote SQL command: SELECT id, dat FROM import_schema."export_schema.aa" 
+1

請生成一個自包含的測試用例作爲單個SQL腳本,該腳本可以從'psql'運行,並將其作爲錯誤報告提交給pgsql-bugs郵件列表。鏈接回到這個帖子的上下文。 –

+0

@CraigRinger我有同樣的問題。這有沒有解決? –

+0

我沒有注意到任何東西。嘗試http://archives.postgresql.org/ –

回答

3

忘記回來的分辨率。在我發佈錯誤報告的時候發現,postgres_fdw上的文檔已更新。請參閱此頁上的「F.31.1.2。對象名稱選項」和schema_name選項:http://www.postgresql.org/docs/current/static/postgres-fdw.html。 我引用郵件列表回覆:

"Use: OPTIONS (schema_name 'export_schema', table_name 'aa'); above. 

     Thanks, 

       Stephen" 

所以解決,只需指定在SCHEMA_NAME選項參數外國架構名稱。

+1

選項之間應該有一個逗號。 – erikcw

+0

修正了它,謝謝! – Alex