Search code examples
ruby-on-railsactiverecordrails-activerecordhstore

Querying hstore with exists?


I have a column as postgres hstore, and want to query it with exists? in my model.

I am using

Model.where("column ? :key", key: "xxx").count

but effectively I just want to know if there at least one with that key, something like

Contact.exists?("column? :key", key: "xxx")

which results an error, because exists? has on argument only.

Any hints?

Thanks so far.


Solution

  • Figured out, simply:

    Model.where("column ? :key", key: "xxx").exists?

    results in a query with LIMIT 1.