Question

I have the following databases:

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)

I have to Join a table in the first to the second database

Here is the sql i have presumed:

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

however i am getting this error:

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
Was it helpful?

Solution

Try like this.

Make alias for remote table and perform the query.

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top