From: Christophe Pettus <xof@thebuild.com>
To: Dirk Mika <Dirk.Mika@mikatiming.de>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Trigger with conditional predicates
Date: Mon, 4 Jan 2021 11:22:48 -0800
Message-ID: <0E26DB9B-0238-4ADF-BA31-4191DD1D27AF@thebuild.com> (raw)
In-Reply-To: <08518A65-1ABB-467E-B12A-03699CF4402C@mikatiming.de>
References: <A4A3D4D4-B8C9-4ED2-B10D-0A908D639F99@mikatiming.de>
<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>
> On Jan 4, 2021, at 11:06, Dirk Mika <Dirk.Mika@mikatiming.de> wrote:
>
> See thread below:
>
> https://www.postgresql.org/message-id/VisenaEmail.26.7cbf2947c8d23ceb.1769a2755ff%40tc7-visena
>
> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: xof@thebuild.com, Dirk.Mika@mikatiming.de, adrian.klaver@aklaver.com
Subject: Re: Trigger with conditional predicates
In-Reply-To: <0E26DB9B-0238-4ADF-BA31-4191DD1D27AF@thebuild.com>
References: <A4A3D4D4-B8C9-4ED2-B10D-0A908D639F99@mikatiming.de> <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> <0E26DB9B-0238-4ADF-BA31-4191DD1D27AF@thebuild.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox