Search Postgresql Archives

Re: How can I merge two tables?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux