Cross database queries

Started by Craig Brydenover 20 years ago3 messagesgeneral
Jump to latest
#1Craig Bryden
postgresql@bryden.co.za

Hi

Suppose I have two databases on one server (lets call them DB_A and DB_B)
and I was to write a cross database query. How do I do this in PostgreSQL?

On MS-SQL I would do something like:

SELECT ta.Field1, ta.Field2, tb.Field2
FROM DB_A.dbo.SomeTable ta
JOIN DB_B.dbo.SomeOtherTable tb
ON ta.Field1 = tb.Field1

Thanks
Craig

#2Sean Davis
sdavis2@mail.nih.gov
In reply to: Craig Bryden (#1)
Re: Cross database queries

On 8/9/05 10:21 AM, "postgresql@bryden.co.za" <postgresql@bryden.co.za>
wrote:

Hi

Suppose I have two databases on one server (lets call them DB_A and DB_B)
and I was to write a cross database query. How do I do this in PostgreSQL?

On MS-SQL I would do something like:

SELECT ta.Field1, ta.Field2, tb.Field2
FROM DB_A.dbo.SomeTable ta
JOIN DB_B.dbo.SomeOtherTable tb
ON ta.Field1 = tb.Field1

See /contrib/dblink in the postgresql source distribution.

Sean

#3Richard Huxton
dev@archonet.com
In reply to: Craig Bryden (#1)
Re: Cross database queries

postgresql@bryden.co.za wrote:

Hi

Suppose I have two databases on one server (lets call them DB_A and DB_B)
and I was to write a cross database query. How do I do this in PostgreSQL?

Either use the dblink module from contrib/ or merge them into one
database but different schemas.

--
Richard Huxton
Archonet Ltd