Re: How do I make a timestamp column default to current time

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "zagman" <daveh(at)allheller(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How do I make a timestamp column default to current time
Date: 2006-03-16 16:41:38
Message-ID: 17573.1142527298@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"zagman" <daveh(at)allheller(dot)net> writes:
> I'm setting up a simple timecard program and I need a column that
> defaults to the current time when a new row is inserted. How can I do
> this I tried setting the default to 'now' but all that does is put the
> time I created the table in each row!

The default has to be a function call, not a literal constant, to work
the way you want. Try

mycol timestamp default now()
or
mycol timestamp default current_timestamp

(the latter is actually a function call, even though the SQL standard
says it has to be spelled without any parentheses)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Ribe 2006-03-16 16:43:34 Error I don't understand, losing synch with server
Previous Message Louis Gonzales 2006-03-16 16:21:37 Re: PostgreSQL scalability concerns