From: | Jeff Hoffmann <jeff(at)propertykey(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | rslifka(at)home(dot)com, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Default timestamp value |
Date: | 2000-06-05 15:52:38 |
Message-ID: | 393BCCC6.7D394758@propertykey.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Tom Lane wrote:
>
> "Rob S." <rslifka(at)home(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-06-05 15:55:26 | Re: SQL functions - bug? |
Previous Message | Tom Lane | 2000-06-05 15:47:55 | Re: cron job INSERT appears to bail. |