Odd behavior of type coercion for datetime

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Odd behavior of type coercion for datetime
Date: 1999-01-24 23:36:17
Message-ID: 14694.917220977@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1999-01-25 01:06:02 Another speedup idea (two, even)
Previous Message Goran Thyni 1999-01-24 22:59:29 alloca (was: Postgres Speed or lack thereof)