Re: the behaviour of timestamp on postgres.

Поиск
Список
Период
Сортировка
От Sebastian Böck
Тема Re: the behaviour of timestamp on postgres.
Дата
Msg-id 411A317F.9080904@freenet.de
обсуждение исходный текст
Ответ на the behaviour of timestamp on postgres.  (Prabu Subroto <prabu_subroto@yahoo.com>)
Список pgsql-general
Prabu Subroto wrote:
> Dear my friends...
>
> I created some tables with field timestamp (datatype
> also timestamp). I mean, I want to have the data when
> each record inserted or modified in the tables.
>
> on MysQL, I just need to define the column (field)
> with datatype "timestamp" and that's all. each time
> new record inserted than the timestamp value will be
> inserted automaticall.  also for the data modification,
> each time the data in the record modified than the
> value of timestamp column will be modified
> automatically.

You can use triggers for that.

Try something like:

CREATE FUNCTION set_timestamp() RETURNS TRIGGER AS '
   BEGIN
     NEW.timestamp := now();
     RETURN NEW;
   END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER insert_timestamp BEFORE INSERT ON table
   FOR EACH ROW EXECUTE PROCEDURE set_timestamp();
CREATE TRIGGER update_timestamp BEFORE UPDATE ON table
   FOR EACH ROW EXECUTE PROCEDURE set_timestamp();

HTH

Sebastian

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: POSIX RE starting with a (
Следующее
От: Prabu Subroto
Дата:
Сообщение: Re: the behaviour of timestamp on postgres.