Re: How can I merge two tables? - Mailing list pgsql-general

From Ondrej Ivanič
Subject Re: How can I merge two tables?
Date
Msg-id CAM6mie+1OsycfWPBg=0EDoJ9bUKUCmyHL1CrH5+yHVEoK6QjTw@mail.gmail.com
Whole thread Raw
In response to How can I merge two tables?  (Jerry LeVan <jerry.levan@gmail.com>)
List pgsql-general
Hi,

On 2 September 2011 03:09, Jerry LeVan <jerry.levan@gmail.com> wrote:
> I keep registration numbers for software and login/passwords for
> various organizations, etc…
>
> 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)

I would copy data from the other machines to the "master" one:

on the "master", under postgres user (data only dump; -a options):
pg_dump -a -h <host1> -t registrations -U <user> <database> -F c |
pg_restore -d <database>
pg_dump -a -h <host2> -t registrations -U <user> <database> -F c |
pg_restore -d <database>
...
pg_dump -a -h <hostN> -t registrations -U <user> <database> -F c |
pg_restore -d <database>

and then do the following:

begin;
insert into tmp select distinct * from registrations;
truncate registrations;
insert into registrations select * from tmp;
commit;

--
Ondrej Ivanic
(ondrej.ivanic@gmail.com)

pgsql-general by date:

Previous
From: Diego Augusto Molina
Date:
Subject: Re: How can I merge two tables?
Next
From: Mike Christensen
Date:
Subject: Re: pgAdmin3 not working with Gnome3