Re: Comparing two tables of different database

From: John Zhang <johnzhang06(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Comparing two tables of different database
Date: 2009-05-01 15:55:24
Message-ID: 618950b80905010855y70609c47j187f16967ab0da77@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Nicholas,

The query is across database query. dblink is needed for that task.

Hope it helps,

John

On Thu, Apr 30, 2009 at 3:07 PM, Edward W. Rouse <erouse(at)comsquared(dot)com>wrote:

> Can’t you use this?
>
>
>
> select name from database2.sr_1 where name not in (select name from
> database2.pr_1);
>
>
>
> My test database VM isn’t running so I can’t test it, but I seem to
> remember that that’s how I did it for a few queries of that type. This is
> assuming the 2 databases are running on the same machine, like the way there
> is template0 as the default and you add addition databases to the same
> ‘instance’. If you are talking about 2 different database servers, then I
> have no idea.
>
>
>
> Edward W. Rouse
>
>
>
> *From:* pgsql-sql-owner(at)postgresql(dot)org [mailto:
> pgsql-sql-owner(at)postgresql(dot)org] *On Behalf Of *Nicholas I
> *Sent:* Thursday, April 30, 2009 6:12 AM
> *To:* Joshua Tolley
> *Cc:* Adam Ruth; Pawel Socha; pgsql-sql(at)postgresql(dot)org
> *Subject:* Re: [SQL] Comparing two tables of different database
>
>
>
> 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
>
>
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Wei Weng 2009-05-01 16:31:12 Re: Comparing two tables of different database
Previous Message Edward W. Rouse 2009-04-30 22:07:41 Re: Comparing two tables of different database