X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 365CB9FB2BE for ; Fri, 4 Aug 2006 13:10:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 73370-08 for ; Fri, 4 Aug 2006 16:10:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 646B89FB393 for ; Fri, 4 Aug 2006 13:10:26 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k74GANVm029506; Fri, 4 Aug 2006 12:10:23 -0400 (EDT) To: "David Garamond" cc: pgsql-sql@postgresql.org Subject: Re: autoupdating mtime column In-reply-to: <7c33d060608040811s6dcaa3abia137188076a76781@mail.gmail.com> References: <7c33d060608040516n799af906sf74e1c645a47caff@mail.gmail.com> <44D34242.6000901@archonet.com> <7c33d060608040811s6dcaa3abia137188076a76781@mail.gmail.com> Comments: In-reply-to "David Garamond" message dated "Fri, 04 Aug 2006 22:11:14 +0700" Date: Fri, 04 Aug 2006 12:10:23 -0400 Message-ID: <29505.1154707823@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200608/39 X-Sequence-Number: 25997 "David Garamond" writes: > On 8/4/06, Richard Huxton wrote: >> Just check for OLD.mtime = NEW.mtime, or am I missing something here? > How do I differentiate between: > UPDATE t SET mtime=mtime ...; > in which mtime is specifically set and should not change, You don't. A trigger has no way to know the history of the row it's looking at --- consider the possibility that it was already modified by earlier triggers. If you are really intent on having a way to suppress the mtime update you could dedicate an additional field to the purpose, eg UPDATE t SET foo=..., bar=..., keepmtime = true ... and in the trigger something like if new.keepmtime then new.keepmtime = false; else new.mtime = now(); As long as nothing else ever touches keepmtime this would work. Personally I'm dubious that it's worth the trouble --- do you have a real use-case for suppressing mtime updates? regards, tom lane