Re: autoupdating mtime column

From: Richard Huxton <dev(at)archonet(dot)com>
To: David Garamond <davidgaramond(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: autoupdating mtime column
Date: 2006-08-04 16:05:50
Message-ID: 44D3705E.9050304@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

David Garamond wrote:
> On 8/4/06, Richard Huxton <dev(at)archonet(dot)com> wrote:
>> David Garamond wrote:
>> > Dear all,
>> >
>> > Please see SQL below. I'm already satisfied with everything except I
>> > wish in
>> > #4, mtime got automatically updated to NOW() if not explicitly SET in
>> > UPDATE
>> > statement. Is there a way to make the mtime column behave more like I
>> > wanted? Thanks in advance.
>>
>> 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, and
>
> UPDATE t SET foo=bar ...;
>
> in which mtime is not mentioned and should be updated automagically to
> NOW().

You can't. The trigger knows nothing about the original statement, just
the old and new tuple values.

You could use SET foo=DEFAULT, but that's neither more or less
convenient than now() in my eyes.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-08-04 16:10:23 Re: autoupdating mtime column
Previous Message David Garamond 2006-08-04 15:51:54 Re: autoupdating mtime column