From: Rob Sargent <robjsargent@gmail.com>
To: Krishnakant Mane <kkmane@riseup.net>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@postgresql.org
Subject: Re: managing primary key conflicts while restoring data to table with existing data
Date: Thu, 26 Sep 2019 09:46:11 -0600
Message-ID: <28585755-0eb7-1b46-9966-a9a0d9acc216@gmail.com> (raw)
In-Reply-To: <90a6191b-9b45-eb43-c3da-6587d7731a84@riseup.net>
References: <399629ce-aefe-d0df-7552-99fc6bc3d958@riseup.net>
<920a0616-125c-6b6a-fd51-abd250a6ee9c@aklaver.com>
<3dcb8017-9126-26ad-dbc8-99ad31b81d0f@riseup.net>
<258FDE31-77A2-4E3B-8BD8-9AB9199999AA@gmail.com>
<f332f9a7-eab2-c9ba-144b-80971cb298c8@aklaver.com>
<a6ee63e1-fde9-4d43-43d2-c67b2987d54a@riseup.net>
<113DEFAE-E197-4966-B97F-C6F1C3471F75@gmail.com>
<90a6191b-9b45-eb43-c3da-6587d7731a84@riseup.net>
>>> --
>>> Regards,
>>> Krishnakant Mane,
>>> Project Founder and Leader,
>>> GNUKhata <https://gnukhata.in/;
>>> //(Opensource Accounting, Billing and Inventory Management Software)//
>> You might think about adding the new UUID column and use the existing
>> primary key to inform the updates in dependent tables. Then remove
>> the old PK column and constraint followed by promoting the UUID to
>> primary key. This could be safely scripted and applied to all
>> instances of your data.
>> That said, this is only truly necessary of you have production
>> databases to worry about.
>
>
> Thanks a million, this is the most logical and safe way.
>
> yes I have a lot of production databases to worry about.
>
> I am only confused about what you mean by "use the existing primary
> key to inform the updates in dependent tables."
>
> Are you refering to a cascading effect?
>
> If yes then does it mean I first program my upgrade script to manually
> go through all new uuid keys and update the same in the depending
> tables with reference to the old primary key working as foreign key in
> those tables?
>
>
It occurs to me you will also need to "duplicate" the columns in which
you have foreign keys. How many tables are there in the affected
schemata and what is the size? Pretty sure you will have to go off-line
to perform this sort of transition. Nearly everything will be touched.
>
> --
> Regards,
> Krishnakant Mane,
> Project Founder and Leader,
> GNUKhata <https://gnukhata.in/;
> //(Opensource Accounting, Billing and Inventory Management Software)//
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: robjsargent@gmail.com, kkmane@riseup.net, adrian.klaver@aklaver.com
Subject: Re: managing primary key conflicts while restoring data to table with existing data
In-Reply-To: <28585755-0eb7-1b46-9966-a9a0d9acc216@gmail.com>
References: <399629ce-aefe-d0df-7552-99fc6bc3d958@riseup.net> <920a0616-125c-6b6a-fd51-abd250a6ee9c@aklaver.com> <3dcb8017-9126-26ad-dbc8-99ad31b81d0f@riseup.net> <258FDE31-77A2-4E3B-8BD8-9AB9199999AA@gmail.com> <f332f9a7-eab2-c9ba-144b-80971cb298c8@aklaver.com> <a6ee63e1-fde9-4d43-43d2-c67b2987d54a@riseup.net> <113DEFAE-E197-4966-B97F-C6F1C3471F75@gmail.com> <90a6191b-9b45-eb43-c3da-6587d7731a84@riseup.net> <28585755-0eb7-1b46-9966-a9a0d9acc216@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox