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 1f9EkK-0003Dl-Hs for pgsql-general@arkaria.postgresql.org; Thu, 19 Apr 2018 18:57:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9EkI-0006pt-Ly for pgsql-general@arkaria.postgresql.org; Thu, 19 Apr 2018 18:57:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9EkI-0006pj-4X for pgsql-general@lists.postgresql.org; Thu, 19 Apr 2018 18:57:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9EkF-0003qX-Eb for pgsql-general@postgresql.org; Thu, 19 Apr 2018 18:57:24 +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 w3JIvH7c024450; Thu, 19 Apr 2018 14:57:17 -0400 From: Tom Lane To: Adrian Klaver cc: PegoraroF10 , pgsql-general@postgresql.org Subject: Re: Problem with trigger makes Detail record be invalid In-reply-to: <7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com> References: <1524160534707-0.post@n3.nabble.com> <7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Thu, 19 Apr 2018 11:24:43 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <24448.1524164237.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 19 Apr 2018 14:57:17 -0400 Message-ID: <24449.1524164237@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 04/19/2018 10:55 AM, PegoraroF10 wrote: >> Is this a bug or it´s mine responsability to check that trigger result ? > Without seeing exactly what the trigger function on Detail is doing that > is not answerable. I think the OP is complaining because his misimplemented trigger can break the consistency of the foreign key constraint. That is not a bug, it's an intentional design decision: triggers are lower-level than foreign key enforcement queries, and fire during such queries. It's easy to construct examples where people would be very unhappy if this were not so, because then FK-driven updates would not be seen by the table's triggers. It does mean that you have to be careful when writing a trigger. (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.) regards, tom lane