Re: timestamp data type? - Mailing list pgsql-novice

From Oliver Elphick
Subject Re: timestamp data type?
Date
Msg-id 1053615834.25709.2174.camel@linda.lfix.co.uk
Whole thread Raw
In response to timestamp data type?  ("psql novice" <psql_novice@operamail.com>)
Responses Re: timestamp data type?
List 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 by date:

Previous
From: "Molenda, Mark P"
Date:
Subject: Problem on Linux
Next
From: Nicholas Allen
Date:
Subject: How to send an email when data is inserted into a table