ROR postgres upsert hash

时间:2016-08-12 08:06:45

标签: ruby-on-rails ruby postgresql upsert

我正试图在这一行中插入:

schema.db

t.text "address_field"

address.rb

serialize :address_field, Hash

迁移文件

enable_extension 'hstore' unless extension_enabled?('hstore')

values = []
Address.find_each do |address|
    new_address_field = {first_line => "Street", second_line => "City" }
    values << [{id: address.id}, {address_field: new_address_field}]
end

Upsert.batch(Address.connection, Address.table_name) do |upsert|
  values.each do |p|
    upsert.row(p[0], p[1])
  end
end

我收到的错误是:

nameError: uninitialized constant PgHstore

1 个答案:

答案 0 :(得分:0)

这是upsert和postgresql的问题。 他们的团队正在研究一些事情,但据我所知尚无新闻报道。

https://github.com/seamusabshere/upsert/issues/60

您可以尝试将数据迁移到其他数据库。