Defaulting to current date

From: "Bryan White" <bryan(at)arcamax(dot)com>
To: "PgSQL-sql" <pgsql-sql(at)postgreSQL(dot)org>
Subject: Defaulting to current date
Date: 1998-10-19 19:31:29
Message-ID: 008e01bdfb97$122cc7c0$a3f0f6ce@bryan.arcamax.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I wnat to have a field with a date/time value that defaults to the time the
record was inserted. I also want to be abled to index this field.

If I create with:
create table test
(
Date timestamp not null default CURRENT_TIMESTAMP
);

The default value works as expected but I cannot create an index:

create index testidx on test (Date);
ERROR: Can't find a default operator class for type 1296.

I have also tried to create the field as a DATETIME field.
create table test
(
Date datetime not null default CURRENT_TIME
);

I can create the index but the field defaults to the table creation time
instead of the insertion time.
I have tried several syntax variations using CURRENT_DATE, CURRENT_TIME,
CURRENT_TIMESTAMP, 'now', and text 'now'. The last one is suggested in the
online documentation, however they refer specifically to v6.4 and I am
running 6.3.2.

It seems like I can index the field or used a default value but not both.
Is this true?

Bryan White
ArcaMax Inc.
Yorktown VA
www.arcamax.com

Browse pgsql-sql by date

  From Date Subject
Next Message Bryan White 1998-10-19 19:37:46 Defaulting to current date
Previous Message David Mansfield 1998-10-19 18:01:10 index not used in like clause...