(:key => :value)", :key => 'CSJ', :value => '0.1') ...">

Postgres HStore Errors - Unknown operator

My ruby ​​code:

Portfolio.where("data @> (:key => :value)",     :key => 'CSJ', :value => '0.1')

      

Creates the following SQL:

"SELECT \"portfolios\".* FROM \"portfolios\"  WHERE (data @> ('CSJ' => '0.1'))"

      

Getting this error:

Error: PG::Error: ERROR:  operator does not exist: unknown => unknown
LINE 1: ...olios".* FROM "portfolios"  WHERE (data @> ('CSJ' => '0.1'))
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "portfolios".* FROM "portfolios"  WHERE (data @> ('CSJ' => '0.1'))

      

Postgresql 9.1.4, Rails 3.2.7 / 8, using the activerecord-postgres-hstore attribute in my model code:

serialize :data, ActiveRecord::Coders::Hstore

      

Help would be appreciated!

+1


source to share


1 answer


You haven't installed the hstore extension to the database used by Rails.

For example, if I speak select 'a' => 'b'

in one of my databases that does not have an hstore, I get this:

=> select 'a' => 'b';
ERROR:  operator does not exist: unknown => unknown
LINE 1: select 'a' => 'b';
                   ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

      



But in another database where hstore is installed, I get this:

=> select 'a' => 'b';
 ?column? 
----------
 "a"=>"b"
(1 row)

      

You need to be done create extension hstore

in a Rails database.

+3


source







All Articles