ruby - How do I get MIN in Postgres to play nice with Rails? -
right now, have enormous query i'm running in rails:
@foo_collection = foo.select(' foos.id, array_agg() some_aggregate, -- 20 of these, they're not problem min(bars.some_date), -- returning wrong type - problem ').joins(' inner bring together bars... -- lot of joins - not problem ').where(' some_conditions ').group(' foos.id ')
this query pulls info want according pgadmin. doesn't translate rails. trying process @foo_collection.some_date
datetime
object create time difference results in this:
undefined method `-' "2014-04-01 16:12:35.461712":string
is there way coax pg output give rails datetime
instead of string
, or have tell rails parse some_date
s string
s?
so far, i've handled having rails convert @foo_collection.some_date
s to_datetime
, to_f
can find time lapses between them. has important overhead - it'd much easier if withdraw datetime
object straight db.
rails pulling field string because you're not querying model defined column type, think best bet might alter query output table , utilize rails model query table.
ruby-on-rails ruby ruby-on-rails-3 postgresql
No comments:
Post a Comment