Re: Updating PK and all FKs to it in CTE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tom Kazimiers <tom(at)voodoo-arts(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Updating PK and all FKs to it in CTE
Date: 2021-07-29 14:51:09
Message-ID: 713691.1627570269@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Kazimiers <tom(at)voodoo-arts(dot)net> writes:
> I am on Postgres 13 and have a problem with updates in a CTE. While certainly
> not generally recommended, I need to update the primary key in a table that is
> referenced by a few other tables. The table definition is attached to the end
> of this email [2]. I'd like to avoid dropping and recreating the constraints or
> even columns, because these tables can become quite large. While I could define
> the FK constraints as ON UPDATE CASCADE, I wonder why an alternative solution
> using a CTE doesn't work:

I tried to reproduce your problem and failed; the attached script
acts as I'd expect. So there must be some moving part you've not
mentioned. Can yo create a similar self-contained example that
fails?

regards, tom lane

Attachment Content-Type Size
fktest.sql text/plain 646 bytes

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Kazimiers 2021-07-29 15:12:48 Re: Updating PK and all FKs to it in CTE
Previous Message Philip Semanchuk 2021-07-29 13:33:16 Re: Low cache hit ratio