I am running a query in rails to get the delay between two events in minutes. I have this working nicely as follows;
orders.select("extract(epoch from (orders.procedure_time - orders.call_time)) / 60 AS delay").map &:delay
where orders is an existing ActiveRecord::Relation object
This works absolutely fine so far except that what I get back is an array of strings rather than integers. It's easy enough to sort out in Ruby - what I have done is the following;
orders.select("extract(epoch from (orders.procedure_time - orders.call_time)) / 60 AS delay").map{|x| x.delay.to_i}
This will do, but I am just wondering if there is a way to get the integers directly from postgres? It seems like it must have the integers initially, but they are being converted to strings which I then have to convert back, which has a whiff of inelegance about it.