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 1f9F7w-00050c-0d for pgsql-general@arkaria.postgresql.org; Thu, 19 Apr 2018 19:21:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9F7u-0004br-Pm for pgsql-general@arkaria.postgresql.org; Thu, 19 Apr 2018 19:21:50 +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 1f9F7u-0004bh-Hk for pgsql-general@lists.postgresql.org; Thu, 19 Apr 2018 19:21:50 +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 1f9F7r-0000lv-9R for pgsql-general@postgresql.org; Thu, 19 Apr 2018 19:21:50 +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 w3JJLgMS002796; Thu, 19 Apr 2018 15:21:42 -0400 From: Tom Lane To: =?UTF-8?Q?Fabr=C3=ADzio_de_Royes_Mello?= cc: Adrian Klaver , PegoraroF10 , Postgres General Subject: Re: Problem with trigger makes Detail record be invalid In-reply-to: References: <1524160534707-0.post@n3.nabble.com> <7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com> <24449.1524164237@sss.pgh.pa.us> Comments: In-reply-to =?UTF-8?Q?Fabr=C3=ADzio_de_Royes_Mello?= message dated "Thu, 19 Apr 2018 16:03:11 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2794.1524165702.1@sss.pgh.pa.us> Date: Thu, 19 Apr 2018 15:21:42 -0400 Message-ID: <2795.1524165702@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?UTF-8?Q?Fabr=C3=ADzio_de_Royes_Mello?= writes: > 2018-04-19 15:57 GMT-03:00 Tom Lane : >> (I'm not sure that this issue is adequately documented, though. >> I'd have expected to find something about it in triggers.sgml and/or >> create_trigger.sgml, but in a quick look neither of them mentions foreign >> keys.) > We don't have it properly documented... at the time I answered this > question on pt-br stackoverflow I noticed the lack o documentation and > unfortunately I completely forgot to propose a small patch for it. It strikes me that there are basically two things a trigger could do to break FK consistency: 1. Turn an FK-commanded update into a no-op by returning NULL. 2. Change the content of the FK-related columns during an FK-commanded update. Both of these apply only to BEFORE ROW triggers, of course. It might not be unreasonable or unduly expensive to throw an error for case #1. I don't think I want to get into the expense of checking for case #2, but covering case #1 would be enough to catch all of the reports of this type of problem that I can remember. IIRC, you can also break FK consistency with poorly-thought-out rules, but given that rules are close-to-deprecated, I'm not very concerned about sanding down rough edges in that case. (But if you feel like writing a documentation patch, please do, because we'd not be likely to back-patch a behavioral change like this even if we get around to making it.) regards, tom lane