我的红宝石代码:
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
帮助将不胜感激!
答案 0 :(得分:3)
您没有在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
。