Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fTidR-0004rQ-A6 for pgsql-general@arkaria.postgresql.org; Fri, 15 Jun 2018 06:55:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fTidQ-0001IL-6G for pgsql-general@arkaria.postgresql.org; Fri, 15 Jun 2018 06:55: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.89) (envelope-from ) id 1fTidP-0001IB-Ul for pgsql-general@lists.postgresql.org; Fri, 15 Jun 2018 06:54:59 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fTidM-0005s9-AZ for pgsql-general@postgresql.org; Fri, 15 Jun 2018 06:54:59 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 79D0941103; Fri, 15 Jun 2018 08:54:55 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id PFyWb0kMM_CS; Fri, 15 Jun 2018 08:54:54 +0200 (CEST) Message-ID: <1529045692.3401.1.camel@cybertec.at> Subject: Re: Trying to understand odd trigger behavior From: Laurenz Albe To: Bruno Wolff III , pgsql-general@postgresql.org Date: Fri, 15 Jun 2018 08:54:52 +0200 In-Reply-To: <20180615040424.GA18759@wolff.to> References: <20180615040424.GA18759@wolff.to> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bruno Wolff III wrote: > I think I know what is happening, but I wanted to see if my understanding > is correct. > > I have a perl after insert trigger for a table with a non-null column element > and I am getting an occasional error when the trigger executes for > printing a null value which is $TD->{new}{element}. However, I do the > insert with an on conflict that converts it into an update. And I have > a before update trigger that blocks changing the record, but returns null > if the old and new records are the same. > > My theory is that the insert trigger is firing even though the action > got changed to an update and that because the update trigger cancelled > the update, there is no new record. So I should just test for $TD->{new} > being doing before doing stuff. > > Does that sound correct? Absolutely, but it should be easy to run a few tests with only a single row insert that confirms your theory. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com