Thread: Querying across databases

Querying across databases

From
Zak McGregor
Date:
Hi all

Does anyone know if  there any way that I can combine tables from 2
databases into one query, or otherwise duplicate the contents (read-only
is fine) of a table in another database? All the databases are on the same
machine and being connected to from localhost.

Any help at all would be very much appreciated.

Thanks

====================================================================
Zak McGregor
--------------------------------------------------------------------
Of course my password is the same as my pet's name.
My macaw's name was Q47pY!3, but I change it every 90 days.
====================================================================


Re: Querying across databases

From
Andrew Gould
Date:
Hi Zak,

One option to move data from table a (ta)in database 1
(db1) to database 2 (db2) is to create ta in db2 and
run the following from the shell:

psql -c "copy ta to stdout;" db1 | psql -c "copy ta
from stdin;" db2

Of course, this is a simplistic solution that assumes
that data will be added but not changed.  I'm not sure
how to tell Postgres to replace unique records with
the newer values.

I'm sure other/better solutions will be posted by more
experienced users.

Best of luck,

Andrew

--- Zak McGregor <zak@mighty.co.za> wrote:
> Hi all
>
> Does anyone know if  there any way that I can
> combine tables from 2
> databases into one query, or otherwise duplicate the
> contents (read-only
> is fine) of a table in another database? All the
> databases are on the same
> machine and being connected to from localhost.
>
> Any help at all would be very much appreciated.
>
> Thanks
>
>
====================================================================
> Zak McGregor
>
--------------------------------------------------------------------
> Of course my password is the same as my pet's name.
>
> My macaw's name was Q47pY!3, but I change it every
> 90 days.
>
====================================================================
>


__________________________________________________
Do You Yahoo!?
Yahoo! Messenger - Talk while you surf!  It's FREE.
http://im.yahoo.com/