Re: Defaulting a column to 'now' - Mailing list pgsql-sql

From Ken Winter
Subject Re: Defaulting a column to 'now'
Date
Msg-id 002301c6019b$d8e8ec60$6603a8c0@kenxp
Whole thread Raw
In response to Re: Defaulting a column to 'now'  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Thanks, Tom (also Keith Worthington and Bricklen Anderson).  That works.

~ Ken

> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.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@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




pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: RETURN SET OF DATA WITH CURSOR
Next
From: "Michael Avila"
Date:
Subject: Need SQL Help Finding Current Status of members