From: Jeff Hoffmann <jeff@propertykey.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: rslifka@home.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Default timestamp value
Date: Mon, 05 Jun 2000 10:52:38 -0500
Message-ID: <393BCCC6.7D394758@propertykey.com> (raw)
References: <001101bfcec0$8683f1e0$39117118@cr699264-a.rct1.bc.wave.home.com>
<12065.960218869@sss.pgh.pa.us>
Tom Lane wrote:
>
> "Rob S." <rslifka@home.com> writes:
> > ...but I still don't see how to have the default value of a timestamp to be
> > the time at which the individual record is inserted. I just get the time I
> > created the table.
> Versions before 7.0 are not entirely consistent about this, but I
> believe the explicit function call now() will work the way you want
> in any version.
you can also use the value CURRENT_TIMESTAMP, which is standard SQL.
you have to be careful about using 'now' as a default, though. i have a
tendancy to put type qualifications on most of the things i write ever
since i had problems with getting an index to be used on an int2 field.
the key to the faq is that you can't put a type qualification after the
'now', otherwise it won't work. so in 7.0, if you create a table like
any of these:
create table foo (f1 int, f2 timestamp default now());
create table foo (f1 int, f2 timestamp default 'now');
create table foo (f1 int, f2 timestamp default CURRENT_TIMESTAMP);
it will work. if you do it like this, it won't:
create table foo (f1 int, f2 timestamp default 'now'::datetime);
create table foo (f1 int, f2 timestamp default 'now'::timestamp);
it will give you the time that the table was created. it's just a
little gotcha that might frustrate people in a similar situation.
jeff
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jeff@propertykey.com, tgl@sss.pgh.pa.us, rslifka@home.com
Subject: Re: Default timestamp value
In-Reply-To: <393BCCC6.7D394758@propertykey.com>
References: <001101bfcec0$8683f1e0$39117118@cr699264-a.rct1.bc.wave.home.com> <12065.960218869@sss.pgh.pa.us> <393BCCC6.7D394758@propertykey.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox