From: Rob Sargent <robjsargent@gmail.com>
To: Fehrle, Brian <bfehrle@comscore.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: Thoughts on how to avoid a massive integer update.
Date: Fri, 8 May 2020 13:49:07 -0600
Message-ID: <8FA70C91-57D3-4AD6-9780-48AD0728CF3C@gmail.com> (raw)
In-Reply-To: <8491BCF6-2163-4765-BCCF-E96B845D7427@comscore.com>
References: <C7D3EE42-66B9-44AF-83F4-CB7F0F42486E@comscore.com>
<129e882d-fe4c-0ce9-1966-acbcbf94c309@aklaver.com>
<0F5992D4-9317-4007-9036-202DC89BA0D8@comscore.com>
<E3B6D3D1-D60E-40D9-8855-B23F7EDBFA8E@gmail.com>
<8491BCF6-2163-4765-BCCF-E96B845D7427@comscore.com>
Well as I said, I think you could add a column to info_table
alter table info_table add orig_id int;
update info_table set orig_id = info_table_sid;
update info_table set info_table_sid = 456 where info_table_sid = 456;
alter table data_table drop reference NOT SQL
alter table data_table make reference to info_table.orig_id NOT SQL
you have to do the second block per orig_id
and the third block per table
at your reports needing the new value will of course need to do the join and get the updated value which now resides in the ill-name info_table_sid.
This leaves “orig_id” as just an id and “info_table_sid” as an editable attribute
Nothing is broken other than the per-table lock while you switch the foreign key
> On May 8, 2020, at 1:36 PM, Fehrle, Brian <bfehrle@comscore.com> wrote:
>
>
>
> From: Rob Sargent <robjsargent@gmail.com <mailto:robjsargent@gmail.com>>
> Date: Friday, May 8, 2020 at 11:05 AM
> To: "Fehrle, Brian" <bfehrle@comscore.com <mailto:bfehrle@comscore.com>>
> Cc: Adrian Klaver <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>>, "pgsql-general@postgresql.org <mailto:pgsql-general@postgresql.org>" <pgsql-general@postgresql.org <mailto:pgsql-general@postgresql.org>>
> Subject: Re: Thoughts on how to avoid a massive integer update.
>
> [External Email]
>
>> Could you show an example table relationship?
>>
>> It’s a simple one-to-many relationship:
>> *Info_table*
>> info_table_sid integer
>>
>>
>> *data_table*
>> data_table_sid integer,
>> info_table_id integer references info_table(info_table_sid),
>>
>>
>>
>
>
> Right, and now you wish to change the values in the referenced table (info_table.info_table_sid) correct?
>
>
> Correct. If info_table.info_table_sid = 123 and many rows in data_table point to it, the ID needs to be changed to 456 in the info_table, as well as all the columns in the data_table.
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, bfehrle@comscore.com
Subject: Re: Thoughts on how to avoid a massive integer update.
In-Reply-To: <8FA70C91-57D3-4AD6-9780-48AD0728CF3C@gmail.com>
References: <C7D3EE42-66B9-44AF-83F4-CB7F0F42486E@comscore.com> <129e882d-fe4c-0ce9-1966-acbcbf94c309@aklaver.com> <0F5992D4-9317-4007-9036-202DC89BA0D8@comscore.com> <E3B6D3D1-D60E-40D9-8855-B23F7EDBFA8E@gmail.com> <8491BCF6-2163-4765-BCCF-E96B845D7427@comscore.com> <8FA70C91-57D3-4AD6-9780-48AD0728CF3C@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