I am using Postgres 9.3 with Rails 4.1.
Suppose I have a table with a properties
hstore colum.
I now want to select a single key inside the hstore column in a scope (or somewhere else..)
What I tried:
Model.select("properties -> 'category'")
What happens: Rails gives me an array like this:
[#<Model id: nil>,
#<Model id: nil>,
#<Model id: nil>,
#<Model id: nil>]
What I want:
[#<Model id: nil, category: 'foo'>,
#<Model id: nil, category: 'bar'>,
#<Model id: nil, category: 'baz'>,
#<Model id: nil, category: 'foo'>]
Try:
=> Model.where("properties @> hstore(?, ?)", 'key', 'value').select(:category)
=> [#<Model id: nil, category: 'foo'>]