Re: Defaulting a column to 'now'

From: "Keith Worthington" <keithw(at)narrowpathinc(dot)com>
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:22:16
Message-ID: 20051214181720.M80996@narrowpathinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 14 Dec 2005 13:10:50 -0500, Ken Winter wrote
> How can a column's default be set to 'now', meaning 'now' as of when each
> row is inserted?
>
> For example, here's a snip of DDL:
>
> create table personal_data (.
>
> effective_date_and_time TIMESTAMP WITH TIME ZONE not null default
> 'now',.
>
> The problem is, when PostgreSQL processes this DDL, it interprets the 'now'
> as the timestamp when the table is created, so that the tables definition
> reads as if the DDL were:
>
> effective_date_and_time TIMESTAMP WITH TIME ZONE not null default '
> 2005-12-14 11:00:16.749616-06 ',
>
> so all of the newly inserted rows get assigned effective_date_and_time
> = '
> 2005-12-14 11:00:16.749616-06 ', which in addition to being wrong
> leads to uniqueness constraint violations.
>
> ~ TIA
>
> ~ Ken

Ken,

effective_date_and_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT
('now'::text)::timestamp(6) with time zone

Kind Regards,
Keith

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2005-12-14 19:13:57 Re: # of 5 minute intervals in period of time ...
Previous Message Tom Lane 2005-12-14 18:15:20 Re: Defaulting a column to 'now'