I store product information, including the year of release of the product, using hstore and postgresql in rails. Now I would like to be able to request all products released before or after a certain year. I can query all records containing the year field in the hstore "data" column using:
Product.where("data ? 'year'")
Due to hstore, the year value is stored as a string. So I tried typing a year for an integer to find records with years greater / less than X:
Product.where("(data ? 'year')::int > 2011")
However, this does not work, I always get an empty array of results in return. What am I doing wrong? Is there any other way to do this?
source
share