Re: Defaulting a column to 'now'

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

Thanks, Tom (also Keith Worthington and Bricklen Anderson). That works.

~ Ken

> -----Original Message-----
> From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
> Sent: Wednesday, December 14, 2005 1:15 PM
> To: Ken Winter
> Cc: PostgreSQL pg-sql list
> Subject: Re: [SQL] Defaulting a column to 'now'
>
> "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

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Avila 2005-12-16 01:31:09 Need SQL Help Finding Current Status of members
Previous Message Richard Huxton 2005-12-15 17:14:20 Re: RETURN SET OF DATA WITH CURSOR