这是我的查询
@pg = ActiveRecord::Base.connection
result = @pg.execute("select sum(col1) AS col1, sum(col2) AS col2 from messages")
现在
result.values
给了我[[val1, val2]]
result.fields
提供[col1, col2]
有没有办法让我们得到与此类似的结果?
{col1 => val1, col2 => val2}
我研究了许多解决方案..没有运气:(
答案 0 :(得分:1)
试试这个
@pg = ActiveRecord::Base.connection
result = @pg.execute("select sum(col1) AS col1, sum(col2) AS col2 from messages").first