mohammad mahmoodi
mohammad mahmoodi

Reputation: 185

How to search in hash column

How to search in hash column on Postgresql ?

product model

serialize :properties, Hash

product migration

add_column :products, :properties, :text

Upvotes: 0

Views: 1416

Answers (2)

hpeev
hpeev

Reputation: 185

Try with

 Product.where("properties->>'foo' = 'bar'")

Upvotes: 0

Alex Kojin
Alex Kojin

Reputation: 5204

You can only use sql LIKE operation to search in the text column.

You can switch to postgresql that has native support of hstore columns or migrate to Rails 5 that support json type column. Rails documentation

Upvotes: 1

Related Questions