Thread: CURRENT_DATE and CURRENT_TIME are broken

CURRENT_DATE and CURRENT_TIME are broken

From
Tom Lane
Date:
... in the sense that they are reduced to constants instantly, rather
than being preserved as function calls.  For example:

regression=# create table foo (f1 time default current_time);
CREATE
regression=# insert into foo default values;
INSERT 618879 1

<< wait a few seconds >>

regression=# insert into foo default values;
INSERT 618880 1
regression=# select * from foo;   f1
----------12:41:4512:41:45
(2 rows)

The problem appears to be that Thomas inserted new pg_proc entries on
11-Nov-2000 that create direct text-to-date and text-to-time
conversions, replacing the old indirect text-to-timestamp-to-date/time
implementation of CURRENT_DATE/TIME.  Unfortunately, whereas
text-to-timestamp is marked noncachable, these new entries are not,
and so the parser decides it can fold date('now'::text) to a constant.

We have three choices:

1. Change these pg_proc entries.  This does not force an initdb,
exactly, but it won't take effect without one either.

2. Change the function calls emitted by the parser for
CURRENT_DATE/TIME.  This doesn't force an initdb either, but it's a
workaround whereas #1 actually fixes the real bug.  (Although #2 might
appear to break stored rules in beta databases, any such rules are
already broken because they've already been reduced to constants...)

3. Ship 7.1 with broken CURRENT_DATE/TIME functionality.

I tend to favor #1, but need agreement to change it.  Comments?
If we do #1, should we bump catversion.h, or leave it alone?
(I'd vote for not changing catversion, I think.)
        regards, tom lane


Re: CURRENT_DATE and CURRENT_TIME are broken

From
Bruce Momjian
Date:
> We have three choices:
> 
> 1. Change these pg_proc entries.  This does not force an initdb,
> exactly, but it won't take effect without one either.
> 
> 2. Change the function calls emitted by the parser for
> CURRENT_DATE/TIME.  This doesn't force an initdb either, but it's a
> workaround whereas #1 actually fixes the real bug.  (Although #2 might
> appear to break stored rules in beta databases, any such rules are
> already broken because they've already been reduced to constants...)
> 
> 3. Ship 7.1 with broken CURRENT_DATE/TIME functionality.
> 
> I tend to favor #1, but need agreement to change it.  Comments?
> If we do #1, should we bump catversion.h, or leave it alone?
> (I'd vote for not changing catversion, I think.)

I vote for anything but #2, and agree catversion should not be changed.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026