Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sKKsx-009bXC-Ld for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jun 2024 16:43:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sKKsu-00B42s-7D for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jun 2024 16:43:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sKKst-00B42k-V6 for pgsql-bugs@lists.postgresql.org; Thu, 20 Jun 2024 16:43:40 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sKKss-002HPE-5e for pgsql-bugs@lists.postgresql.org; Thu, 20 Jun 2024 16:43:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 45KGharu366499; Thu, 20 Jun 2024 12:43:36 -0400 From: Tom Lane To: exclusion@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18517: Dropping a table referenced by an initially deferred foreign key fails with an error In-reply-to: <18517-af2d19882240902c@postgresql.org> References: <18517-af2d19882240902c@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 20 Jun 2024 11:00:01 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <366497.1718901816.1@sss.pgh.pa.us> Date: Thu, 20 Jun 2024 12:43:36 -0400 Message-ID: <366498.1718901816@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form 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