Ruby on Rails 3.1与Postgres 9.1.4搭配时,hstore未知运算符错误如何解决?

2026-04-11 17:191阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计398个文字,预计阅读时间需要2分钟。

Ruby on Rails 3.1与Postgres 9.1.4搭配时,hstore未知运算符错误如何解决?

我正在尝试将hstore数据列添加到现有的STI模型中。类似于Postgres HStore错误——未知操作符。尽管我知道我已经安装了hstore扩展,并且已经删除了数据库并重新建立,但错误仍然存在。

我正在尝试将hstore数据列添加到现有的STI模型中.

类似于Postgres HStore Errors – Unknown Operator但据我所知,我已经安装了hstore扩展.我已经删除了数据库并从迁移重建它而没有错误,但规格仍然失败.

Mac OS X 10.8.2 Rails 3.1.10 psql (PostgreSQL) 9.1.4

user.rb

Ruby on Rails 3.1与Postgres 9.1.4搭配时,hstore未知运算符错误如何解决?

has_many :targets def complete_targets targets.where("data @> (:key => :value)", key: 'complete', value: 'true') end

targets.rb

belongs_to :user serialize :data, ActiveRecord::Coders::Hstore

setup_hstore迁移:

class SetupHstore < ActiveRecord::Migration def self.up execute "CREATE EXTENSION IF NOT EXISTS hstore" end def self.down execute "DROP EXTENSION IF EXISTS hstore" end end

添加数据列迁移:

class AddDataToRecords < ActiveRecord::Migration def change add_column :records, :data, :hstore end end

添加索引迁移:

class AddHstoreIndexes < ActiveRecord::Migration def up execute "CREATE INDEX records_gin_data ON records USING GIN(data)" end def down execute "DROP INDEX records_gin_data" end end

错误:

ActiveRecord::StatementInvalid: PG::Error: ERROR: operator does not exist: unknown => unknown LINE 1: ...records"."user_id" = 244 AND (data @> ('complete' => 'true')...

尝试通过直接查询创建扩展时的Navicat输出:

CREATE EXTENSION hstore Error : ERROR: extension "hstore" already exists 也许这是一个简单的数据类型问题,请尝试:

data @> ('complete'::text => 'true'::text)

但是=>运算符已弃用(并已在9.2中删除),最好使用hstore()格式:

(data @> hstore('complete','true'))

本文共计398个文字,预计阅读时间需要2分钟。

Ruby on Rails 3.1与Postgres 9.1.4搭配时,hstore未知运算符错误如何解决?

我正在尝试将hstore数据列添加到现有的STI模型中。类似于Postgres HStore错误——未知操作符。尽管我知道我已经安装了hstore扩展,并且已经删除了数据库并重新建立,但错误仍然存在。

我正在尝试将hstore数据列添加到现有的STI模型中.

类似于Postgres HStore Errors – Unknown Operator但据我所知,我已经安装了hstore扩展.我已经删除了数据库并从迁移重建它而没有错误,但规格仍然失败.

Mac OS X 10.8.2 Rails 3.1.10 psql (PostgreSQL) 9.1.4

user.rb

Ruby on Rails 3.1与Postgres 9.1.4搭配时,hstore未知运算符错误如何解决?

has_many :targets def complete_targets targets.where("data @> (:key => :value)", key: 'complete', value: 'true') end

targets.rb

belongs_to :user serialize :data, ActiveRecord::Coders::Hstore

setup_hstore迁移:

class SetupHstore < ActiveRecord::Migration def self.up execute "CREATE EXTENSION IF NOT EXISTS hstore" end def self.down execute "DROP EXTENSION IF EXISTS hstore" end end

添加数据列迁移:

class AddDataToRecords < ActiveRecord::Migration def change add_column :records, :data, :hstore end end

添加索引迁移:

class AddHstoreIndexes < ActiveRecord::Migration def up execute "CREATE INDEX records_gin_data ON records USING GIN(data)" end def down execute "DROP INDEX records_gin_data" end end

错误:

ActiveRecord::StatementInvalid: PG::Error: ERROR: operator does not exist: unknown => unknown LINE 1: ...records"."user_id" = 244 AND (data @> ('complete' => 'true')...

尝试通过直接查询创建扩展时的Navicat输出:

CREATE EXTENSION hstore Error : ERROR: extension "hstore" already exists 也许这是一个简单的数据类型问题,请尝试:

data @> ('complete'::text => 'true'::text)

但是=>运算符已弃用(并已在9.2中删除),最好使用hstore()格式:

(data @> hstore('complete','true'))