Re: timestamp data type?

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: timestamp data type?
Дата
Msg-id 1053615834.25709.2174.camel@linda.lfix.co.uk
обсуждение исходный текст
Ответ на timestamp data type?  ("psql novice" <psql_novice@operamail.com>)
Ответы Re: timestamp data type?  (Nabil Sayegh <postgresql@e-trolley.de>)
Список pgsql-novice
On Thu, 2003-05-22 at 07:51, psql novice wrote:
> Is there a timestamp data type that will automatically update the date
> and time when a record gets inserted/updated. I know MySQL has this
> feature, i was wondering if postgresql had a equivalent data type
>
> MySQL Doc
> "The TIMESTAMP column type provides a type that you can use to
> automatically mark INSERT or UPDATE operations with the current date
> and time."

There is no type that does this.

The way to do it on INSERT is:

CREATE TABLE xxx (
   ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
   ...);

This can be overridden if the insert provides a value for the field.

If you need it not to be overrideable or to be changed on update as
well, you need a trigger to fire BEFORE UPDATE OR INSERT

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "We are troubled on every side, yet not distressed; we
      are perplexed, but not in despair; persecuted, but not
      forsaken; cast down, but not destroyed; Always bearing
      about in the body the dying of the Lord Jesus, that
      the life also of Jesus might be made manifest in our
      body."        II Corinthians 4:8-10


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

Предыдущее
От: "Molenda, Mark P"
Дата:
Сообщение: Problem on Linux
Следующее
От: Nicholas Allen
Дата:
Сообщение: How to send an email when data is inserted into a table