Re: PostgreSQL v11.3 - Records are deleted from child table if partition key of parent table is changed

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: "Rozboril, Robert" <robert(dot)rozboril(at)dxc(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: PostgreSQL v11.3 - Records are deleted from child table if partition key of parent table is changed
Date: 2019-06-20 18:00:56
Message-ID: 20190620180056.GA25386@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2019-Jun-20, Rozboril, Robert wrote:

> ALTER TABLE polf ADD CONSTRAINT polf_po_id_fk FOREIGN KEY (po_id) REFERENCES pof(po_id) ON DELETE CASCADE;
> ALTER TABLE polt ADD CONSTRAINT polt_po_id_fk FOREIGN KEY (po_id) REFERENCES pot(po_id) ON DELETE CASCADE;

Hmm, yeah, I wouldn't expect this to work well -- the UPDATEs done by
the cascade action would not see that there is another partition. If
you were declaring the PK and FK constraints on the parent tablej, it
should work correctly:

ALTER TABLE pol ADD CONSTRAINT pol_pkey PRIMARY KEY (pol_id);
ALTER TABLE pol ADD CONSTRAINT pol_po_id_fk FOREIGN KEY (po_id) REFERENCES po(po_id) ON DELETE CASCADE;
(similarly for the "po" table).

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2019-06-20 18:46:27 BUG #15864: problems with the instalation of PostgreSQL 9.4
Previous Message Alvaro Herrera 2019-06-20 17:09:45 Re: Logging corruption error codes