Re: PostgreSQL trigger how to detect a column value explicitely modified

From: PALAYRET Jacques <jacques(dot)palayret(at)meteo(dot)fr>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dominique Devienne <ddevienne(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: PostgreSQL trigger how to detect a column value explicitely modified
Date: 2025-11-05 09:24:50
Message-ID: 503814564.256630396.1762334690791.JavaMail.zimbra@meteo.fr
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I think you knew that I don't really want to create a function in language C to handle and test the values of the columns in the SQL query. For me, it is much easier to use the solution of the trigger " BEFORE|AFTER UPDATE OF col ".
Joke aside, I hadn't thought of that ; it is an excellent idea (simple solution).
I tested it ; it works as expected.

Thanks to people who replied.
Regards.

----- Mail original -----
De: "Laurenz Albe" <laurenz(dot)albe(at)cybertec(dot)at>
À: "PALAYRET Jacques" <jacques(dot)palayret(at)meteo(dot)fr>, pgsql-general(at)lists(dot)postgresql(dot)org
Envoyé: Mardi 4 Novembre 2025 18:29:05
Objet: Re: PostgreSQL trigger how to detect a column value explicitely modified

On Tue, 2025-11-04 at 12:48 +0000, PALAYRET Jacques wrote:
> In a trigger body, is there a simple way to know if a column value has been explicitely modified ?
> Explicitely modified ; in others words, typically indicated in the SET clause of the UPDATE.
> A simple way ; I mean without analysing the SQL statement which can be very difficult according to the statement.

Unless you want to write a C trigger function you can use

CREATE TRIGGER ... BEFORE|AFTER UPDATE OF col ON tab FOR EACH ROW ...

Then the trigger function will only be called if the SET clause of UPDATE
contains the column "col".

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2025-11-05 15:36:58 Re: Index corruption issue after migration from RHEL 7 to RHEL 9 (PostgreSQL 11 streaming replication)
Previous Message Bala M 2025-11-05 06:27:22 Re: Index corruption issue after migration from RHEL 7 to RHEL 9 (PostgreSQL 11 streaming replication)