Re: Default timestamp value

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: rslifka(at)home(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Default timestamp value
Date: 2000-06-05 15:27:49
Message-ID: 12065.960218869@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"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. 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, see
http://www.postgresql.org/docs/faq-english.html#4.22

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-06-05 15:47:55 Re: cron job INSERT appears to bail.
Previous Message p.lam 2000-06-05 15:05:57 CREATE FUNCTION- Table as argument