Re: autoupdating mtime column

Поиск
Список
Период
Сортировка
От David Garamond
Тема Re: autoupdating mtime column
Дата
Msg-id 7c33d060608040851x525e7f82l5f058d259c011a8c@mail.gmail.com
обсуждение исходный текст
Ответ на Re: autoupdating mtime column  ("Rodrigo De León" <rdeleonp@gmail.com>)
Список pgsql-sql
On 8/4/06, Rodrigo De León <rdeleonp@gmail.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

В списке pgsql-sql по дате отправления:

Предыдущее
От: "Rodrigo De León"
Дата:
Сообщение: Re: autoupdating mtime column
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: autoupdating mtime column