Reputation: 828
This is my query
@pg = ActiveRecord::Base.connection
result = @pg.execute("select sum(col1) AS col1, sum(col2) AS col2 from messages")
now
result.values
gives me [[val1, val2]]
result.fields
gives [col1, col2]
is there a way we can get result similar to this ?
{col1 => val1, col2 => val2}
i looked into many solutions.. no luck :(
Upvotes: 0
Views: 32
Reputation: 2675
Try this
@pg = ActiveRecord::Base.connection
result = @pg.execute("select sum(col1) AS col1, sum(col2) AS col2 from messages").first
Upvotes: 1