activerecord-postgres-hstore icon indicating copy to clipboard operation
activerecord-postgres-hstore copied to clipboard

How does one use bound variables when searching for keys?

Open chrisbloom7 opened this issue 12 years ago • 1 comments

Given your example Person.where("data ? 'foo'"), how would one rewrite that to use a bound variable? Person.where("data \? ?") results in ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (1 for 2).

chrisbloom7 avatar Feb 20 '13 20:02 chrisbloom7

Instead of using ? use key/value pairs.

Person.where("date ? :key", :key => 'foo')

davidbegin avatar Sep 14 '13 20:09 davidbegin