Re: BUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: exclusion(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error
Date: 2024-06-20 16:43:36
Message-ID: 366498.1718901816@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The following script:
> CREATE TABLE pkt (id int PRIMARY KEY);
> CREATE TABLE fkt (id int PRIMARY KEY, fk int REFERENCES pkt INITIALLY
> DEFERRED);
> INSERT INTO pkt VALUES (1);
> BEGIN;
> INSERT INTO fkt VALUES (101, 1);

> DROP TABLE pkt CASCADE;
> COMMIT;

> fails on commit with a weird error:
> ERROR: relation 16390 has no triggers

Oh, interesting. Furthermore, if I add an unrelated trigger to fkt
so that there's still a trigdesc, then I reach

ERROR: XX000: could not find trigger 42452
LOCATION: AfterTriggerExecute, trigger.c:4303

So what this demonstrates is that we should not consider it an
error if afterTriggerInvokeEvents finds an event for a trigger
that no longer exists.

Perhaps an alternative could be to run through the pending events
at DROP time and throw an error if there's an unfired event for the
trigger. That doesn't sound better to me though. I see no very
good reason why we shouldn't allow the above sequence of commands
and treat the constraint as no longer to be enforced.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Melanie Plageman 2024-06-21 00:33:59 Re: relfrozenxid may disagree with row XIDs after 1ccc1e05ae
Previous Message Tom Lane 2024-06-20 15:50:57 Re: BUG #18516: Foreign key data integrity is not validated when reenabled the trigger on tables