Converting time interval to double precision of time unit

Поиск
Список
Период
Сортировка
От Mike Toews
Тема Converting time interval to double precision of time unit
Дата
Msg-id 22f0a52d1003300929w37da164fk20e0f0bf87bc33f4@mail.gmail.com
обсуждение исходный текст
Ответы Re: Converting time interval to double precision of time unit  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Список pgsql-general
I'm using 8.3, and I'm trying to work with the interval type, and I
can't seem to get things right. I've been all over the docs[1,2], and
there is no mention on how this can be done.

While I can get:
SELECT '3 day 2 hour 34 minute'::interval

.. how can then get the fractional hours of this time interval in
double precision (or seconds, minutes, years, decades, etc.)?

Do I really need to extract the time subcomponents and do the math myself?

For example:
SELECT extract(day from interval)*24 + extract(hour from interval) +
extract(minute from interval)/60 as hours
FROM (SELECT '3 day 2 hour 34 minute'::interval) AS foo;

This seem like a bad hack, and I can't believe a function doesn't
already exist to properly cast a time interval to a fractional unit of
time, so I thought I'd check up to see if there is a better solution.

Thanks,

-Mike

[1] http://www.postgresql.org/docs/8.3/static/functions-datetime.html
[2] http://www.postgresql.org/docs/8.3/static/datatype-datetime.html

В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Dblink vs calling a function that returns void
Следующее
От: Andy Colson
Дата:
Сообщение: Re: User action accounting