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 1vGZlC-001Cgf-FK for pgsql-general@arkaria.postgresql.org; Wed, 05 Nov 2025 09:24:57 +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 1vGZlB-001ZUN-CR for pgsql-general@arkaria.postgresql.org; Wed, 05 Nov 2025 09:24:56 +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 1vGZlB-001ZUD-0i for pgsql-general@lists.postgresql.org; Wed, 05 Nov 2025 09:24:56 +0000 Received: from zcsmtaf02-pub.meteo.fr ([137.129.63.6]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vGZl7-005Yey-0N for pgsql-general@lists.postgresql.org; Wed, 05 Nov 2025 09:24:55 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by zcsmtaf02-pub.meteo.fr (Postfix) with ESMTP id 53751431E34D; Wed, 5 Nov 2025 09:24:51 +0000 (GMT) Received: from zcsmtaf02-pub.meteo.fr ([127.0.0.1]) by localhost (zcsmtaf02.meteo.fr [127.0.0.1]) (amavis, port 10032) with ESMTP id ReocWlNT3w8A; Wed, 5 Nov 2025 09:24:51 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcsmtaf02-pub.meteo.fr (Postfix) with ESMTP id 3A76F457C988; Wed, 5 Nov 2025 09:24:51 +0000 (GMT) X-Virus-Scanned: amavis at meteo.fr Received: from zcsmtaf02-pub.meteo.fr ([127.0.0.1]) by localhost (zcsmtaf02.meteo.fr [127.0.0.1]) (amavis, port 10026) with ESMTP id spsj92l2m7-a; Wed, 5 Nov 2025 09:24:51 +0000 (GMT) Received: from zcsmsm04.meteo.fr (zcsmsm04.meteo.fr [172.24.3.124]) by zcsmtaf02-pub.meteo.fr (Postfix) with ESMTP id 27C65431E34D; Wed, 5 Nov 2025 09:24:51 +0000 (GMT) Date: Wed, 5 Nov 2025 09:24:50 +0000 (GMT) From: PALAYRET Jacques To: Laurenz Albe , Tom Lane , Dominique Devienne Cc: pgsql-general@lists.postgresql.org Message-ID: <503814564.256630396.1762334690791.JavaMail.zimbra@meteo.fr> In-Reply-To: <425c6f01eecaf7ef85989b775fe9e3fd200f65f7.camel@cybertec.at> References: <616435641.255753519.1762260528389.JavaMail.zimbra@meteo.fr> <425c6f01eecaf7ef85989b775fe9e3fd200f65f7.camel@cybertec.at> Subject: Re: PostgreSQL trigger how to detect a column value explicitely modified MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.24.2.157] X-Mailer: Zimbra 9.0.0_GA_4583 (ZimbraWebClient - FF128 (Win)/9.0.0_GA_4583) Thread-Topic: PostgreSQL trigger how to detect a column value explicitely modified Thread-Index: oclSp4MHGx8fXrZnDcZ+WQBETgYt0w== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 solu= tion). I tested it ; it works as expected. Thanks to people who replied. Regards. ----- Mail original ----- De: "Laurenz Albe" =C3=80: "PALAYRET Jacques" , pgsql-general@lists= .postgresql.org Envoy=C3=A9: Mardi 4 Novembre 2025 18:29:05 Objet: Re: PostgreSQL trigger how to detect a column value explicitely mod= ified 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 be= en explicitely modified ? > Explicitely modified ; in others words, typically indicated in the SET cl= ause of the UPDATE. > A simple way ; I mean without analysing the SQL statement which can be ve= ry 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