Postgres HStore错误 – 未知运算符
我的ruby代码:
Portfolio.where("data @> (:key => :value)", :key => 'CSJ', :value => '0.1')
生成以下SQL:
"SELECT \"portfolios\".* FROM \"portfolios\" WHERE (data @> ('CSJ' => '0.1'))"
想出这个错误:
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,使用activerecord-postgres-hstore gem,我的模型代码中包含以下内容:
serialize :data, ActiveRecord::Coders::Hstore
帮助将不胜感激!
您没有在Rails正在使用的数据库中安装hstore扩展。
例如,如果我在我的一个没有hstore的数据库中select 'a' => 'b'
,我会得到:
=> 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.
但是在另一个安装了hstore的数据库中,我得到了这个:
=> select 'a' => 'b'; ?column? ---------- "a"=>"b" (1 row)
您需要在Rails数据库中create extension hstore
一个create extension hstore
。