Re: [SQL] now() returning int4 - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] now() returning int4
Date
Msg-id 12189.949371217@sss.pgh.pa.us
Whole thread Raw
In response to Re: [SQL] now() returning int4  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
List pgsql-sql
"Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu> writes:
>> db=> SELECT * FROM test WHERE date < now()::int4;

> SELECT * FROM test WHERE date < int(now());
> Works here.

I believe this is a bug in the typecasting code --- when you try to
cast a value to another type that the system considers bit-compatible
with the original type, the parser knows that no actual type conversion
work is required.  But it then decides it doesn't have to do *anything*,
and effectively drops the cast entirely.  It should be marking the
expression result as being of the destination type so that subsequent
processing works as the user intends.

Related example:

regression=# select now()::int4;       ?column?
------------------------2000-01-31 21:07:36-05
(1 row)

regression=# select int(now());   int
-----------949370865
(1 row)

Both of these should yield int-formatted output, IMHO.

I have this on my to-fix list for 7.0.
        regards, tom lane


pgsql-sql by date:

Previous
From: Ray Plante
Date:
Subject: GROUP BY: v6.1 vs. v6.5.2
Next
From: Tom Lane
Date:
Subject: Re: [SQL] GROUP BY: v6.1 vs. v6.5.2