From: | Oliver Elphick <olly(at)lfix(dot)co(dot)uk> |
---|---|
To: | psql novice <psql_novice(at)operamail(dot)com> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: timestamp data type? |
Date: | 2003-05-22 15:03:54 |
Message-ID: | 1053615834.25709.2174.camel@linda.lfix.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(dot)Elphick(at)lfix(dot)co(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Nicholas Allen | 2003-05-22 15:41:43 | How to send an email when data is inserted into a table |
Previous Message | Molenda, Mark P | 2003-05-22 14:33:30 | Problem on Linux |