Rails 3.1, Postgres 9.1.4, unknown hstore operator error
I am trying to add an hstore column to an existing STI model.
Like Postgres, HStore Errors is an unknown operator , but as far as I can tell, I've installed the hstore extension. I dumped the database and rebuilt it from migration with no errors, but the specs still don't work.
Mac OS X 10.8.2
Rails 3.1.10
psql (PostgreSQL) 9.1.4
user.rb
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
Add data column wrap:
class AddDataToRecords < ActiveRecord::Migration
def change
add_column :records, :data, :hstore
end
end
Add index migration:
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
Mistake:
ActiveRecord::StatementInvalid:
PG::Error: ERROR: operator does not exist: unknown => unknown
LINE 1: ...records"."user_id" = 244 AND (data @> ('complete' => 'true')...
Navicat output when trying to create an extension via direct request:
CREATE EXTENSION hstore Error : ERROR: extension "hstore" already exists
+3
source to share