简体   繁体   English

Postgres HStore错误 - 未知运算符

[英]Postgres HStore Errors - Unknown Operator

My ruby code: 我的红宝石代码:

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

Generates the following SQL: 生成以下SQL:

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

Comes up with 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 activerecord-postgres-hstore gem with the following in my model code: Postgresql 9.1.4,Rails 3.2.7 / 8,在我的模型代码中使用activerecord-postgres-hstore gem和以下内容:

serialize :data, ActiveRecord::Coders::Hstore

Help would be appreciated! 帮助将不胜感激!

You didn't install the hstore extension in the database that Rails is using. 您没有在Rails正在使用的数据库中安装hstore扩展。

For example, if I say select 'a' => 'b' in one of my databases that doesn't have hstore, I get this: 例如,如果我说在我的一个没有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.

But in another database that does have hstore installed, I get this: 但是在另一个安装了hstore的数据库中,我得到了这个:

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

You need to do a create extension hstore in your Rails database. 您需要在Rails数据库中create extension hstore一个create extension hstore

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM