RKs
RKs

Reputation: 173

Convert interval to number in postgresql

I have created a query which sums up the interval for respective date-time,

select sum(ts_polling) / count(ts_polling) as Average_Queue_Wait_Time ,  cast(time_start AS Date)
  from callcent_queuecalls group by cast(time_start AS date) order by time_start DESC;

enter image description here

Is there a way to convert Average_Queue_Wait_Time from interval data type to number ?

Upvotes: 3

Views: 17031

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246033

You can get the number of seconds in an interval like this:

SELECT EXTRACT(epoch FROM INTERVAL '1 day 30 minutes 1.234 seconds');

┌───────────┐
│ date_part │
├───────────┤
│ 88201.234 │
└───────────┘
(1 row)

Upvotes: 8

Related Questions