Re: Trigger with conditional predicates

Поиск
Список
Период
Сортировка
От Christophe Pettus
Тема Re: Trigger with conditional predicates
Дата
Msg-id 0E26DB9B-0238-4ADF-BA31-4191DD1D27AF@thebuild.com
обсуждение исходный текст
Ответ на Re: Trigger with conditional predicates  (Dirk Mika <Dirk.Mika@mikatiming.de>)
Список pgsql-general

> 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
of0. 
-- 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
whenrun.  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
valuedesired 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
logicchange that can happen here. 

Best,
--
-- Christophe Pettus
   xof@thebuild.com




В списке pgsql-general по дате отправления:

Предыдущее
От: Dirk Mika
Дата:
Сообщение: Re: Trigger with conditional predicates
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: Trigger with conditional predicates