Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHamc-00058I-P8 for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Oct 2018 20:38:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHama-0006oI-Q9 for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Oct 2018 20:38:36 +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.89) (envelope-from ) id 1gHama-0006oB-Ji for pgsql-bugs@lists.postgresql.org; Tue, 30 Oct 2018 20:38:36 +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.89) (envelope-from ) id 1gHamU-0002GE-BV for pgsql-bugs@postgresql.org; Tue, 30 Oct 2018 20:38:36 +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 w9UKcQvA017501; Tue, 30 Oct 2018 16:38:26 -0400 From: Tom Lane To: Jim Finnerty cc: pgsql-bugs@postgresql.org Subject: Re: BEFORE triggers that return NULL can circumvent referential integrity In-reply-to: <1540931408693-0.post@n3.nabble.com> References: <1540931408693-0.post@n3.nabble.com> Comments: In-reply-to Jim Finnerty message dated "Tue, 30 Oct 2018 13:30:08 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17499.1540931906.1@sss.pgh.pa.us> Date: Tue, 30 Oct 2018 16:38:26 -0400 Message-ID: <17500.1540931906@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jim Finnerty writes: > The non compliance issue reported previously (concerning the potential > firing of user-defined AFTER triggers prior to firing immediate-mode foreign > key constraint triggers) still guaranteed that the database would be left in > a consistent state at the end of each statement. Even though you could run > some SQL inside of a trigger that had access to inconsistent state, if that > state was inconsistent at the end of the statement the statement would still > fail; however, exploiting a PostgreSQL feature of BEFORE triggers allows > users to run SQL statements that do not fail or rollback, and that can > commit the database in a state that is inconsistent with the foreign key > constraints. Yes. This is known, and documented, and we don't really intend to change it. > This is clearly not the > intended behavior according to the PostgreSQL documentation What documentation? If there's a contrary promise somewhere, we need to fix that. The CREATE TRIGGER page is pretty clear about it though: There is also nonstandard behavior if BEFORE triggers modify rows or prevent updates during an update that is caused by a referential action. This can lead to constraint violations or stored data that does not honor the referential constraint. regards, tom lane