From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ken Winter <ken@sunward.org>
Cc: PostgreSQL pg-sql list <pgsql-sql@postgresql.org>
Subject: Re: Defaulting a column to 'now'
Date: Wed, 14 Dec 2005 13:15:20 -0500
Message-ID: <22427.1134584120@sss.pgh.pa.us> (raw)
In-Reply-To: <003501c600d9$b799a1c0$6603a8c0@kenxp>
References: <003501c600d9$b799a1c0$6603a8c0@kenxp>
"Ken Winter" <ken@sunward.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, ken@sunward.org
Subject: Re: Defaulting a column to 'now'
In-Reply-To: <22427.1134584120@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox