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 1f9WVi-0004Yx-2Y for pgsql-general@arkaria.postgresql.org; Fri, 20 Apr 2018 13:55:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f9WVg-0000Al-W5 for pgsql-general@arkaria.postgresql.org; Fri, 20 Apr 2018 13:55:32 +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 1f9WVf-000074-4l for pgsql-general@lists.postgresql.org; Fri, 20 Apr 2018 13:55:32 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f9WVZ-0001IL-K3 for pgsql-general@postgresql.org; Fri, 20 Apr 2018 13:55:30 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 11E4521F20; Fri, 20 Apr 2018 09:55:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 20 Apr 2018 09:55:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=iGw3FhbFAw79ouGvmcy9lyB6BGh8B KcJPQgkH/3/S4Q=; b=WIMAHTU5t6Msi0u2kHVHBBnEDVgy4eQJ4eFh6cH6Ai0OL rE6qywV+sLYrPWxKkzLfe1Z8yBS1ACouqMBUmDDQEBHYaQJyuCTEofaX7XD1T2sg 8JtOe+Dp1+QBBeyoh6sVnsKUdpoI2XIYncGYlEkJV4lWILpt5kHN6F0mj8yi2Rtx Fq8vsdvAyhUg3C0Wnb9xqfgIkRASlBijEI62bLsJ4gmUygIXX2F6jNNUsQf/4kPS GT2n3WGnDkV7gbBUpuwt2spYuqxYu1bOAYiWjT5J+CxhtrUnnvP4vKDUYmNdPEIP zoyyUsqk1cJ3XHhDGEf4hdBUjsiQpQht1TD5aHrGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=iGw3Fh bFAw79ouGvmcy9lyB6BGh8BKcJPQgkH/3/S4Q=; b=h7uA+p+46Z42kWiL9KyHap tGl2lAEDXr4fd6jFONvD7GSilcOafxtnNT87k679OgitHSr1E69poaTj2ODNK3Zz NCBRCAn3YyN607wu081fJcvBWAUtX1Nry75qlkVRlGpMxcLBrrc7YXMz/y5ShQrm iBRAHtNRhDeHDWCUvnk3JXaxtMsMqlYHOd6ETEcZLuFBV6h1VwsOuAHf1u5SrN+V llHDJ7d9AtCfODKXOWatG7Wr4ndkCVe0fQNSeTt2Xe8Cn4dC9ER+bWYfmi6lYQ3m AzFjqqf8VjOK+lIC9oQmH5tiJ78jL1gXSqjGBIE6OpEhJIMTEvXpdscBM3OWe/kw == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 486CC102AD; Fri, 20 Apr 2018 09:55:22 -0400 (EDT) Subject: Re: Problem with trigger makes Detail record be invalid To: PegoraroF10 , pgsql-general@postgresql.org References: <1524160534707-0.post@n3.nabble.com> <7cb5806e-7371-5c19-1c7b-b8ac556bdfb5@aklaver.com> <24449.1524164237@sss.pgh.pa.us> <2795.1524165702@sss.pgh.pa.us> <1524188994110-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <4f528d7d-90d0-55d1-f017-b72d730080db@aklaver.com> Date: Fri, 20 Apr 2018 06:55:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1524188994110-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/19/2018 06:49 PM, PegoraroF10 wrote: > Correct, that delete done a partial commit. And this is absolutely > unacceptable. Yet a known possible outcome. See the section on Triggers towards bottom of page: https://en.wikipedia.org/wiki/Foreign_key > I know I did that trigger incorrectly but referential integrity is > obligatory. I would agree if the FK relationship was entirely driven by the system trigger e.g: alter table Detail add constraint FKMasterDetail foreign key (Master_ID) references Master(ID) on update cascade on delete cascade; As soon as you added your UPDATE/DELETE trigger you took on responsibility for how the data was passed around. I understand that this was not communicated as well as it should be in the docs. > Imagine if I have a database crash and need to restore as soon as possible. > How much time I´ll spend removing those records from a backup to get entire > database restored properly. Myself, having written more then my fair share of poorly thought out trigger functions, I test new ones extensively before I release them into the wild. > > Well, I´ll review all my triggers. And I have hundreds of them. > > > -- Adrian Klaver adrian.klaver@aklaver.com