Re: Synchronizing a table that is in two different databases : Need to dump a table as inserts from db1 and change the insert statements into UPDATE statements

From: Khangelani Gama <kgama(at)argility(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Synchronizing a table that is in two different databases : Need to dump a table as inserts from db1 and change the insert statements into UPDATE statements
Date: 2014-03-28 10:07:58
Message-ID: 531dd89555c5986101531a3bada10f0a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Chris or anyone who can help

When I try this just below, it complains about foo (new table created in
db2) , saying *ERROR: schema foo does not exist*. I got stuck on this error
for a while now but still trying to see why but still no luck so far. If
you have something please help

begin;

update foo

set br_desc = bar.br_desc

, br_active = bar.br_active

(rest of columns)

where foo.br_cde = bar.br_cde;

*From:* Khangelani Gama [mailto:kgama(at)argility(dot)com <kgama(at)argility(dot)com>]
*Sent:* Friday, March 28, 2014 7:52 AM
*To:* 'chris(at)chriscurvey(dot)com'; 'pgsql'
*Subject:* RE: [GENERAL] Synchronizing a table that is two different
databases : Need to dump a table a insert from db1 and change the insert
statements into UPDATE statements

Thank you very much, I will try option 2 because option 1 will give me FK
constrains. These two databases are not exactly similar, but few tables on
each of these Databases needs to be exactly the same, in this case db1 is
the reliable one, hence that's why I need to update db2 with what it's in
db1.

*From:* ccurvey(at)gmail(dot)com [mailto:ccurvey(at)gmail(dot)com <ccurvey(at)gmail(dot)com>] *On
Behalf Of *Chris Curvey
*Sent:* Thursday, March 27, 2014 3:08 PM
*To:* Khangelani Gama; pgsql
*Subject:* Re: [GENERAL] Synchronizing a table that is two different
databases : Need to dump a table a insert from db1 and change the insert
statements into UPDATE statement

(For clarity, I'm going to call the table in question "foo".)

Option 1: If you just want to do a full copy of db1.foo to db2.foo, then
do that. Dump foo from db1, truncate foo in db2 and load db2.foo from the
dump. But you might not be able to do that (foreign keys and such). In
that case..

Option 2: Dump the table from db1, then load it into a table with a
different name ("bar") in db2. Then you can do this:

begin;

update foo

set br_desc = bar.br_desc

, br_active = bar.br_active

(rest of columns)

where foo.br_cde = bar.br_cde;

insert into foo (br_cde, br_desc, br_active, ...)

select br_cde, br_desc, br_active, ....

from bar

where not exists

( select *

from foo

where foo.br_cde = bar.br_cde);

commit;

CONFIDENTIALITY NOTICE
The contents of and attachments to this e-mail are intended for the addressee only, and may contain the confidential
information of Argility (Proprietary) Limited and/or its subsidiaries. Any review, use or dissemination thereof by anyone
other than the intended addressee is prohibited.If you are not the intended addressee please notify the writer immediately
and destroy the e-mail. Argility (Proprietary) Limited and its subsidiaries distance themselves from and accept no liability
for unauthorised use of their e-mail facilities or e-mails sent other than strictly for business purposes.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message lst_hoe02 2014-03-28 10:35:22 Re: [GENERAL] openvz and shared memory trouble
Previous Message Khangelani Gama 2014-03-28 09:59:50 Re: Synchronizing a table that is in two different databases : Need to dump a table as inserts from db1 and change the insert statements into UPDATE statements