Odd behavior of type coercion for datetime - Mailing list pgsql-hackers

From Tom Lane
Subject Odd behavior of type coercion for datetime
Date
Msg-id 14694.917220977@sss.pgh.pa.us
Whole thread Raw
Responses Re: [HACKERS] Odd behavior of type coercion for datetime  (Bruce Momjian <maillist@candle.pha.pa.us>)
List pgsql-hackers
With 6.4 or current sources, I find that coercing a datetime to float8
is a no-op:

treetest=> create table dt1 (t datetime);
CREATE
treetest=> insert into dt1 values('now');
INSERT 159593 1
treetest=> select t from dt1;
t
----------------------------
Sun Jan 24 18:28:50 1999 EST
(1 row)

treetest=> select t::float8 from dt1;
?column?
----------------------------
Sun Jan 24 18:28:50 1999 EST
(1 row)


I was expecting to get either some numerical equivalent to the date
(seconds since 1970 would do nicely, but I'll take the internal rep...)
or an error message saying "no such conversion available".  I was
certainly not expecting to find that the result was still a datetime,
but such it appears to be.  This is a bug, wouldn't you say?

What's even more curious is that coercing to int4 does produce
something numeric:

treetest=> select t::int4 from dt1;    int4
---------
-29464270
(1 row)

        regards, tom lane


pgsql-hackers by date:

Previous
From: Goran Thyni
Date:
Subject: alloca (was: Postgres Speed or lack thereof)
Next
From: Tom Lane
Date:
Subject: Another speedup idea (two, even)