2013-12-22 60 views
0

我有以下數據庫:對兩個數據庫連接使用PostgreSQL和DBLINK

server_a { 
    a_t1 (a_t1_a1, a_t1_a2); 
    a_t2 (a_t2_a1, a_t2_a2); 
} 
server_b { 
    b_t1 (b_t1_a1, b_t1_a2); 
    b_t2 (b_t2_a1, b_t2_a2); 
} 

attribute 1 = serial not null (primary) 
attribute 2 = character varying(50) 

我必須在第一表加入到第二個數據庫

這裏是SQL我已經認爲:

Select * from a_t1 full outer join dblink('dbname=server_b','select * from b_t1') 
where a_t1.a_t1_a1>1 

但是我得到這個錯誤:

ERROR: syntax error at or near "where" 
LINE 1: ...in dblink('dbname=server_b','select * from b_t1') where a_t1... 
                  ^
********** Error ********** 

ERROR: syntax error at or near "where" 
SQL state: 42601 
Character: 83 

回答

2

試試這個。

爲遠程表製作別名並執行查詢。

Select * from a_t1 full outer join dblink('dbname=server_b','select * from b_t1') as tmp_b_t1 (a1 serial not null (primary) , a2 character varying(50)) 
where a_t1.tmp_b_t1>1