Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Ron
On 12/7/20 3:40 PM, Tom Lane wrote: Ron writes: That works *sometimes*, but not when we *really* want it to work. test=# begin transaction; BEGIN test=# ALTER TABLE sales_header DETACH PARTITION sales_header_202001; ERROR:  removing partition "sales_header_202001" violates foreign key constrain

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Tom Lane
Ron writes: > That works *sometimes*, but not when we *really* want it to work. > test=# begin transaction; > BEGIN > test=# ALTER TABLE sales_header DETACH PARTITION sales_header_202001; > ERROR:  removing partition "sales_header_202001" violates foreign key > constraint "sales_detail_cust_id_o

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Ron
On 12/7/20 1:27 PM, Tom Lane wrote: Ron writes: Neither technique worked. test=# ALTER TABLE sales_detail ALTER CONSTRAINT fk_sales_detail_sales_header DEFERRABLE INITIALLY DEFERRED; ALTER TABLE Hmm, reproduced here. There seems to be some kind of bug in ALTER CONSTRAINT --- it looks like it'

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Adrian Klaver
On 12/7/20 1:15 PM, Ron wrote: On 12/7/20 1:27 PM, Tom Lane wrote: Ron writes: Neither technique worked. test=# ALTER TABLE sales_detail ALTER CONSTRAINT fk_sales_detail_sales_header DEFERRABLE INITIALLY DEFERRED; ALTER TABLE Hmm, reproduced here.  There seems to be some kind of bug in ALTER

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Ron
On 12/7/20 1:27 PM, Tom Lane wrote: Ron writes: Neither technique worked. test=# ALTER TABLE sales_detail ALTER CONSTRAINT fk_sales_detail_sales_header DEFERRABLE INITIALLY DEFERRED; ALTER TABLE Hmm, reproduced here. There seems to be some kind of bug in ALTER CONSTRAINT --- Do I need to fi

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Tom Lane
Ron writes: > Neither technique worked. > test=# ALTER TABLE sales_detail ALTER CONSTRAINT > fk_sales_detail_sales_header DEFERRABLE INITIALLY DEFERRED; > ALTER TABLE Hmm, reproduced here. There seems to be some kind of bug in ALTER CONSTRAINT --- it looks like it's updated all the child FKs s

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Ron
On 12/7/20 12:19 PM, Thomas Kellerer wrote: Ron schrieb am 07.12.2020 um 19:15: Referenced by: TABLE "sales_detail" CONSTRAINT "fk_sales_detail_sales_header"    FOREIGN KEY (cust_id, order_ts) REFERENCES sales_header(cust_id, order_ts) *DEFERRABLE* I think if you only mention "de

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Ron
On 12/7/20 12:19 PM, Thomas Kellerer wrote: Ron schrieb am 07.12.2020 um 19:15: Referenced by: TABLE "sales_detail" CONSTRAINT "fk_sales_detail_sales_header"    FOREIGN KEY (cust_id, order_ts) REFERENCES sales_header(cust_id, order_ts) *DEFERRABLE* I think if you only mention "de

Re: Deferrable FK not behaving as expected.

2020-12-07 Thread Thomas Kellerer
Ron schrieb am 07.12.2020 um 19:15: Referenced by:     TABLE "sales_detail" CONSTRAINT "fk_sales_detail_sales_header"   FOREIGN KEY (cust_id, order_ts) REFERENCES sales_header(cust_id, order_ts) *DEFERRABLE* I think if you only mention "deferrable" this is the same as "deferrable ini

Deferrable FK not behaving as expected.

2020-12-07 Thread Ron
v12.5 I added a deferrable FK constraint on sales_detail to ensure that no one can delete records from sales_header when an associated sales_detail record exists. That works perfectly. The problem is that try to delete parent records before the child records *inside a transaction* also fail