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
|
Список | 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 по дате отправления: