Re: Determining if a table really changed in a trigger

Поиск
Список
Период
Сортировка
От Mark Dilger
Тема Re: Determining if a table really changed in a trigger
Дата
Msg-id 6526D693-D520-4B94-B44F-4A2770FBF778@enterprisedb.com
обсуждение исходный текст
Ответ на Re: Determining if a table really changed in a trigger  (Mitar <mmitar@gmail.com>)
Ответы Re: Determining if a table really changed in a trigger  (Michael Lewis <mlewis@entrata.com>)
Re: Determining if a table really changed in a trigger  (Mitar <mmitar@gmail.com>)
Список pgsql-general

> On Oct 26, 2021, at 3:39 PM, Mitar <mmitar@gmail.com> wrote:
>
> On Tue, Oct 26, 2021 at 10:55 PM Mark Dilger
> <mark.dilger@enterprisedb.com> wrote:
>> Note that there is a performance cost to storing the old rows using the REFERENCING clause of the trigger
>
> Yea, by moving the trivial update check to a rule, I need REFERENCING
> only to see if there were any changes at all. This seems a bit
> excessive. Is there a way to check if any rows have been affected by
> an UPDATE inside a per statement trigger without using REFERENCING?

I felt the same way about it, but after glancing quickly through the code and docs nothing jumped out.  The information
isclearly available, as it gets returned at the end of the UPDATE statement in the "UPDATE 0" OR "UPDATE 3", but I
don'tsee how to access that from the trigger.  I might have to submit a patch for that if nobody else knows a way to
getit.  (Hopefully somebody will respond with the answer...?) 

> I also notice that you check if a table has any rows with:
>
> SELECT true INTO have_rows FROM old_values LIMIT 1;
> IF have_rows THEN ...
>
> Is this just a question of style or is this a better approach than my:
>
> PERFORM * FROM old_values LIMIT 1;
> IF FOUND THEN ...

There is no reason to prefer my spelling of that over yours.  I didn't put much thought into it, but rather just wrote
itthe first way that occurred to me. 

—
Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company






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

Предыдущее
От: Mitar
Дата:
Сообщение: Re: Determining if a table really changed in a trigger
Следующее
От: Michael Lewis
Дата:
Сообщение: Re: Determining if a table really changed in a trigger