Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwVRP-0006wC-E4 for pgsql-general@arkaria.postgresql.org; Mon, 04 Jan 2021 19:22:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kwVRO-0001FD-CD for pgsql-general@arkaria.postgresql.org; Mon, 04 Jan 2021 19:22:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwVRO-0001F4-58 for pgsql-general@lists.postgresql.org; Mon, 04 Jan 2021 19:22:54 +0000 Received: from smtp84.iad3b.emailsrvr.com ([146.20.161.84]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwVRL-0004cz-Pm for pgsql-general@lists.postgresql.org; Mon, 04 Jan 2021 19:22:53 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp11.relay.iad3b.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 6F259401B8; Mon, 4 Jan 2021 14:22:50 -0500 (EST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.5\)) Subject: Re: Trigger with conditional predicates From: Christophe Pettus In-Reply-To: <08518A65-1ABB-467E-B12A-03699CF4402C@mikatiming.de> Date: Mon, 4 Jan 2021 11:22:48 -0800 Cc: Adrian Klaver , "pgsql-general@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <0E26DB9B-0238-4ADF-BA31-4191DD1D27AF@thebuild.com> References: <7097609B-DCC8-49B8-932C-35A3D7D6A405@thebuild.com> <28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de> <0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com> <08518A65-1ABB-467E-B12A-03699CF4402C@mikatiming.de> To: Dirk Mika X-Mailer: Apple Mail (2.3445.9.5) X-Classification-ID: e30957e1-810a-4f5d-b023-ffdb7f951410-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Jan 4, 2021, at 11:06, Dirk Mika wrote: >=20 > See thread below: >=20 > = https://www.postgresql.org/message-id/VisenaEmail.26.7cbf2947c8d23ceb.1769= a2755ff%40tc7-visena >=20 > I found that thread already, but It doesn't not provide a solution to = my problem. One possibility, which is admittedly very hacky, is: -- Create a new column which is a flag (or bitmap) of other columns that = need to be managed in this way, with a default of 0. -- Have two EACH ROW triggers: * The first is ON UPDATE OF the actual column to managed, and sets the = appropriate flag or bitmap in the flag column when run. This flags that = the application has updated the column. * The second, which runs always, checks that flag, and if it is set, = clears it; otherwise, it sets the column to the value desired if the = application didn't change it. Of course, the order of execution of these triggers matters; PostgreSQL = executes triggers at the same level alphabetically. Now, this is a pretty high-overhead way of handling it, and it is = probably better to see if there is an application logic change that can = happen here. Best, -- -- Christophe Pettus xof@thebuild.com