Re: [HACKERS] Why DEFAULT text 'now' does not work for TIMESTAMP columns

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Why DEFAULT text 'now' does not work for TIMESTAMP columns
Date: 1999-07-19 01:48:08
Message-ID: 19990718204807.A18807@wallace.ece.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Jul 18, 1999 at 06:19:41PM -0400, Tom Lane wrote:
<excellent problem analysis snipped>
>
> I am about to commit parser fixes that ensure a DEFAULT value is
> correctly coerced to the column type when it is used (that is,
> transformInsertStatement now does a coerce_type rather than just
> assuming what is in pg_attrdef is the right type). So, one possible
> approach is to remove the coercion code from StoreAttrDefault
> altogether. That would mean that
> field1 datetime 'now'
> would start acting the same as
> field1 datetime text 'now'
> currently does: both of them would be coerced to datetime at runtime,
> not when the constraint expression is created. Given the frequency
> with which newbies complain about the current behavior, I think that
> that might be a Good Thing. But it would be a change in behavior,
> and I suppose there are scenarios where you'd like to be able to get
> the old behavior.
>
> Comments?

My only comment: it seems to me that after your fix, one could still get the
old behavior via something like:
field1 datetime now()
or perhaps:
field1 datetime 'now'::datetime
correct? And the default behavior will now be what most naive users
expect. As long as a workaround exists for the cases where someone cares
about the table definition time, I wouldn't worry about staying 'bug'
(or misfeature?) compatible, unless it's an official, committee backed
SQL standard misfeature, of course. ;-) Sounds good to me.

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Vadim Mikheev 1999-07-19 01:56:24 Re: [HACKERS] Fix up for BTP_CHAIN problems
Previous Message cc123 1999-07-19 00:35:24 Toner Supplies