Defaulting a column to 'now'

From: "Ken Winter" <ken(at)sunward(dot)org>
To: "PostgreSQL pg-sql list" <pgsql-sql(at)postgresql(dot)org>
Subject: Defaulting a column to 'now'
Date: 2005-12-14 18:10:50
Message-ID: 003501c600d9$b799a1c0$6603a8c0@kenxp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bricklen Anderson 2005-12-14 18:15:08 Re: Defaulting a column to 'now'
Previous Message Michael Fuhr 2005-12-14 17:53:07 Re: Finding out to which table a specific row belongs