timestamp data type?
timestamp data type?
От:
"psql novice" <psql_novice@operamail.com>
Дата:
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." -- ____________________________________________ http://www.operamail.com Get OperaMail Premium today - USD 29.99/year Powered by Outblaze
Re: timestamp data type?
От:
Oliver Elphick <olly@lfix.co.uk>
Дата:
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
Re: timestamp data type?
От:
Nabil Sayegh <postgresql@e-trolley.de>
Дата:
Am Don, 2003-05-22 um 17.03 schrieb Oliver Elphick: > CREATE TABLE xxx ( > ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, > ...); BTW: Is there a difference between DEFAULT now() and DEFAULT CURRENT_TIMESTAMP ? -- e-Trolley Sayegh & John, Nabil Sayegh Tel.: 0700 etrolley /// 0700 38765539 Fax.: +49 69 8299381-8 PGP : www.e-trolley.de