Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bzU6H-00032X-N1 for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Oct 2016 19:43:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bzU6G-0000GR-GL for pgsql-bugs@arkaria.postgresql.org; Wed, 26 Oct 2016 19:43:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bzU6G-0000GK-22 for pgsql-bugs@postgresql.org; Wed, 26 Oct 2016 19:43:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bzU6D-0007pu-4R for pgsql-bugs@postgresql.org; Wed, 26 Oct 2016 19:42:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u9QJgrVA024946; Wed, 26 Oct 2016 15:42:53 -0400 From: Tom Lane To: James Parks cc: pgsql-bugs@postgresql.org Subject: Re: AfterTriggerSaveEvent() Error on altered foreign key cascaded delete In-reply-to: References: Comments: In-reply-to James Parks message dated "Wed, 26 Oct 2016 12:21:49 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24944.1477510973.1@sss.pgh.pa.us> Date: Wed, 26 Oct 2016 15:42:53 -0400 Message-ID: <24945.1477510973@sss.pgh.pa.us> X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org James Parks writes: > I *believe* we've found a slight inconsistency with the handling of foreign > keys in the situation of cascaded deletes. Here is a POC to motivate the > discussion: > ... > -- Method A > -- ALTER TABLE bar ADD CONSTRAINT foo_fkey FOREIGN KEY (foo_id) REFERENCES > foo (id) ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY > DEFERRED; > -- Method B > ALTER TABLE bar ADD CONSTRAINT foo_fkey FOREIGN KEY (foo_id) REFERENCES foo > (id) ON DELETE CASCADE ON UPDATE NO ACTION; > ALTER TABLE bar ALTER CONSTRAINT foo_fkey DEFERRABLE INITIALLY DEFERRED; > If you run the above code, you should get something like this: > psql:test.sql:24: ERROR: AfterTriggerSaveEvent() called outside of query > CONTEXT: SQL statement "DELETE FROM ONLY "public"."bar" WHERE $1 > OPERATOR(pg_catalog.=) "foo_id"" > However, if you swap out the foreign key constraint initialization methods > (see "Method A" and "Method B" above) the AfterTriggerSaveEvent() error > disappears: Hm. A quick test suggests that Method B leaves the deferrability flags for the FK's triggers set incorrectly. That's a bug for sure. I'm not certain offhand if the error message indicates an additional problem (ie, should the triggers work when set up this way?) regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs