Re: Default timestamp value - Mailing list pgsql-sql

From Tom Lane
Subject Re: Default timestamp value
Date
Msg-id 12065.960218869@sss.pgh.pa.us
Whole thread Raw
In response to Default timestamp value  ("Rob S." <rslifka@home.com>)
Responses RE: Default timestamp value  ("Rob S." <rslifka@home.com>)
List pgsql-sql
"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.  Specifically, what to put where the '?' is at.

> ... "TimeDate" TIMESTAMP DEFAULT ? ...

In 7.0 either "'now'" or "now()" should work, eg

regression=# create table foo (f1 int, f2 timestamp default now());
CREATE
regression=# insert into foo values(1);
INSERT 395192 1
regression=# insert into foo values(2);
INSERT 395193 1
regression=# select * from foo;f1 |           f2
----+------------------------ 1 | 2000-06-05 11:15:25-04 2 | 2000-06-05 11:15:28-04
(2 rows)

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.

BTW, this *is* covered in the FAQ, seehttp://www.postgresql.org/docs/faq-english.html#4.22
        regards, tom lane


pgsql-sql by date:

Previous
From: p.lam@altavista.net
Date:
Subject: CREATE FUNCTION- Table as argument
Next
From: Tom Lane
Date:
Subject: Re: cron job INSERT appears to bail.