Re: Comparing two tables of different database

From: Nicholas I <nicholas(dot)domnic(dot)i(at)gmail(dot)com>
To: Joshua Tolley <eggyknap(at)gmail(dot)com>
Cc: Adam Ruth <adamruth(at)mac(dot)com>, Pawel Socha <pawel(dot)socha(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Comparing two tables of different database
Date: 2009-04-30 10:12:16
Message-ID: e13d0d10904300312j5ec7baa1l3ae91724f6f5dbf8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi All,

For example,

There are two database. database1 and database 2;

database1 has a table called pr_1 with the columns, id,name and time.
database2 has a table called sr_1 with the_columns id,name and time.

i would like to find out the differences that is, find the names that
are not in sr_1 but in pr_1.
we can achieve this by the query,

select name from sr_1 where name not in (select name from pr_1);
the above query will work in case of two tables in the same database.

But the problem is, these two tables are in different database. i did
not understand about the dblink.

is there any exaples on dblink. can we do it without using dblink.

-Nicholas I

On Thu, Apr 30, 2009 at 9:07 AM, Joshua Tolley <eggyknap(at)gmail(dot)com> wrote:

> On Thu, Apr 30, 2009 at 08:20:02AM +1000, Adam Ruth wrote:
> > The simple answer is to pg_dump both tables and compare the output
> with
> > diff.
> > Other than that, I think you'll need a custom program.
>
> For all but the strictest definition of "identical", that won't work.
> Tables may easily contain the same information, in different on-disk
> order, and pg_dump will most likely give the data to you in an order
> similar to its ordering on disk.
>
> Something like a COPY (<query>) TO <file>, where <query> includes an
> ORDER BY clause, might give you a suitable result from both tables, on
> which you could then take a checksum.
>
> - Josh / eggyknap
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkn5HQoACgkQRiRfCGf1UMPcagCfQDRa2bXPRjgSuVsrFYTnGTTC
> rhoAnAlGwp0vSKd2uspyFvxCTfugG6Yh
> =LO6r
> -----END PGP SIGNATURE-----
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jasen Betts 2009-04-30 12:05:03 Re: Comparing two tables of different database
Previous Message Joshua Tolley 2009-04-30 03:37:48 Re: Comparing two tables of different database