Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vGIdq-00C13f-9T for pgsql-general@arkaria.postgresql.org; Tue, 04 Nov 2025 15:08:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vGIdp-00EZ1r-3t for pgsql-general@arkaria.postgresql.org; Tue, 04 Nov 2025 15:08:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vGIdo-00EZ1j-PJ for pgsql-general@lists.postgresql.org; Tue, 04 Nov 2025 15:08:11 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vGIdm-005QFc-0V for pgsql-general@lists.postgresql.org; Tue, 04 Nov 2025 15:08:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5A4F89cL518935; Tue, 4 Nov 2025 10:08:09 -0500 From: Tom Lane To: PALAYRET Jacques cc: pgsql-general@lists.postgresql.org Subject: Re: PostgreSQL trigger how to detect a column value explicitely modified In-reply-to: <616435641.255753519.1762260528389.JavaMail.zimbra@meteo.fr> References: <616435641.255753519.1762260528389.JavaMail.zimbra@meteo.fr> Comments: In-reply-to PALAYRET Jacques message dated "Tue, 04 Nov 2025 12:48:48 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <518933.1762268889.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 04 Nov 2025 10:08:09 -0500 Message-ID: <518934.1762268889@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PALAYRET Jacques writes: > In a trigger body, is there a simple way to know if a column value has b= een explicitely modified ? = > Explicitely modified ; in others words, typically indicated in the SET c= lause 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 =3D 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