From: | "David Garamond" <davidgaramond(at)gmail(dot)com> |
---|---|
To: | Rodrigo De León <rdeleonp(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: autoupdating mtime column |
Date: | 2006-08-04 15:51:54 |
Message-ID: | 7c33d060608040851x525e7f82l5f058d259c011a8c@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 8/4/06, Rodrigo De León <rdeleonp(at)gmail(dot)com> wrote:
>
> How about:
>
> create or replace function
> update_times()
> returns trigger as $$
> begin
> if TG_OP='INSERT' then
> new.ctime = coalesce(new.ctime,now());
> new.mtime = coalesce(new.mtime,now());
> elsif TG_OP='UPDATE' then
> new.ctime = old.ctime;
> new.mtime = now();
> end if;
> return new;
> end;
> $$ language plpgsql;
>
But that would disallow setting mtime and ctime to arbitrary values, which I
want to permit. But ctime and mtime should be set to current time if not
specified in INSERT, and mtime to current time if not specified in UPDATE. I
guess what I want is the MySQL's TIMESTAMP autoupdate behaviour, whichI
can't seem to be able to emulate in Postgres, because there's no information
given about which columns are specified in the SET clause, only the NEW and
OLD records.
--
dave
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2006-08-04 16:05:50 | Re: autoupdating mtime column |
Previous Message | Rodrigo De León | 2006-08-04 15:39:07 | Re: autoupdating mtime column |