Re: How can I merge two tables?

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: How can I merge two tables?
Дата
Msg-id 1315015688.8877.20.camel@jdavis-ux.asterdata.local
обсуждение исходный текст
Ответ на How can I merge two tables?  (Jerry LeVan <jerry.levan@gmail.com>)
Список pgsql-general
On Thu, 2011-09-01 at 13:09 -0400, Jerry LeVan wrote:
> As time goes by the tables on the various computers get out of
> sync.
>
> Is there an elegant way I can get all of the differences (uniquely)
> merged into a single table?

You can try a query involving NOT EXISTS, combined with dblink:

http://www.postgresql.org/docs/current/static/dblink.html

Effectively the query would be something like:

INSERT INTO registrations
 SELECT * FROM
  -- fetch remote version of table
  dblink(..., "SELECT * FROM registrations") AS remote_reg(...)
 WHERE NOT EXISTS
  (SELECT 1 FROM registrations local_reg
   WHERE local_reg.id = remote_reg.id);

(disclaimer: I didn't test this query out, it's just for illustrating
the idea).

Regards,
    Jeff Davis


В списке pgsql-general по дате отправления:

Предыдущее
От: Rich Shepard
Дата:
Сообщение: Re: Looking for an intro-to-SQL book which is PostgreSQL-friendly
Следующее
От: Bret Fledderjohn
Дата:
Сообщение: Re: Looking for an intro-to-SQL book which is PostgreSQL-friendly