Thread: Query two database at once

Query two database at once

From
Stéphane RIFF
Date:
Hi,

I want to ewecute a query on two database like this :

SELECT * FROM table01 T1, table02 T2 WHERE T1.gid=T2.gid AND 
T2.my_field='".$value."'

The problem is that table01 is in a different database than table02 and 
i don't know how to telle postgresql
to look in two db.
Is there a solution other than execute two query ?
Thanks


Re: [despammed] Query two database at once

From
Andreas Kretschmer
Date:
am  02.05.2005, um 17:36:05 +0200 mailte Stéphane RIFF folgendes:
> Hi,
> 
> I want to ewecute a query on two database like this :
> 
> SELECT * FROM table01 T1, table02 T2 WHERE T1.gid=T2.gid AND 
> T2.my_field='".$value."'
> 
> The problem is that table01 is in a different database than table02 and i 
> don't know how to telle postgresql
> to look in two db.
> Is there a solution other than execute two query ?

The answer is: yes and no.

No: PG can't connect to two databases and do a select across.
Yes: take a look at the contrib on dblink.

You should look in the archiv of the list, Tom Lane and other people
described the way with dblink in the past.


Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net===    Schollglas Unternehmensgruppe    ===