Re: Defaulting a column to 'now'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ken Winter" <ken(at)sunward(dot)org>
Cc: "PostgreSQL pg-sql list" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Defaulting a column to 'now'
Date: 2005-12-14 18:15:20
Message-ID: 22427.1134584120@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Ken Winter" <ken(at)sunward(dot)org> writes:
> How can a column's default be set to 'now', meaning 'now' as of when each
> row is inserted?

You need a function, not a literal constant. The SQL-spec way is
CURRENT_TIMESTAMP
(which is a function, despite the spec's weird idea that it should be
spelled without parentheses); the traditional Postgres way is
now()

Either way only sets an insertion default, though. If you want to
enforce a correct value on insertion, or change the value when the
row is UPDATEd, you need to use a trigger.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Keith Worthington 2005-12-14 18:22:16 Re: Defaulting a column to 'now'
Previous Message Bricklen Anderson 2005-12-14 18:15:08 Re: Defaulting a column to 'now'