Odd behavior of type coercion for datetime

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Odd behavior of type coercion for datetime
Дата
Msg-id 14694.917220977@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: [HACKERS] Odd behavior of type coercion for datetime  (Bruce Momjian <maillist@candle.pha.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Goran Thyni
Дата:
Сообщение: alloca (was: Postgres Speed or lack thereof)
Следующее
От: Tom Lane
Дата:
Сообщение: Another speedup idea (two, even)