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

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: PALAYRET Jacques <jacques.palayret@meteo.fr>
Cc: pgsql-general@lists.postgresql.org
Date: 2025-11-04T15:08:09Z
Lists: pgsql-general
PALAYRET Jacques <jacques.palayret@meteo.fr> writes:
> 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. 

I believe that an ON UPDATE trigger coded in C can access a bitmapset
that shows which column(s) are targeted in the SET clause; but we've
not exposed that to PL/pgSQL or other higher-level languages.

There are of course a bunch of definitional issues.  Should
"UPDATE ... SET x = x" count as an update?  What if some earlier
(... or later ...) BEFORE trigger changes a column?  We don't
provide any help for those cases either.

I think most people settle for testing "OLD.col IS DISTINCT FROM
NEW.col", which you could argue is a good operational definition
of whether the column changed.

			regards, tom lane