ruby-on-rails – 在PostgreSQL中使用Sequel gem插入一个数组

我在代码中创建了一个包含以下模式的表
DB.create_table :Pokemon do
  primary_key :id
  String :first_name
  String :last_name
  String :email
  String :zipcode
  String :company_name
  String :google_profile
  String :skype
  String :phone
  String :about
  String :linkedin_profile_url
  String :company_url
  column :needs,'Text[]'
  column :offering,'Text[]'
end

为了需要和提供我插入一个字符串数组与以下代码

pokes=DB[:Pokemon];
off=['hello1','hello2']
nee= ['need1','need2']
pokes.insert(:first_name => 'abcd',:last_name => 'mehandiratta',:offering => off,:needs =>  nee)

当我运行它我得到一个错误

PG::Error: ERROR:  column "offering" is of type text[] but expression is of type record (Sequel::DatabaseError)
LINE 1: ...fering","needs") VALUES ('abcd','mehandiratta',('hello1',...
                                                             ^
HINT:  You will need to rewrite or cast the expression.
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:145:in `execute_query'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/database/logging.rb:33:in `log_yield'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:145:in `execute_query'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:132:in `execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:111:in `check_disconnect_errors'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:132:in `execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:413:in `_execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:242:in `execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:425:in `check_database_errors'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:242:in `execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/database/connecting.rb:236:in `synchronize'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/connection_pool/threaded.rb:104:in `hold'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/database/connecting.rb:236:in `synchronize'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:242:in `execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/dataset/actions.rb:801:in `execute'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/postgres.rb:525:in `fetch_rows'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/dataset/actions.rb:860:in `returning_fetch_rows'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/dataset/actions.rb:341:in `insert'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/shared/postgres.rb:1060:in `insert'
    from /var/lib/gems/1.8/gems/sequel-3.43.0/lib/sequel/adapters/shared/postgres.rb:1069:in `insert'
    from hello.rb:10

任何人都可以告诉一个合适的方法如何在Sequel gem中插入数组以及如何在列中添加Text数组

解决方法

相关文章

以下代码导致我的问题: class Foo def initialize(n=0) @n = n end attr_accessor :n d...
这是我的spec文件,当为上下文添加测试“而不是可单独更新用户余额”时,我得到以下错误. require 's...
我有一个拦截器:DevelopmentMailInterceptor和一个启动拦截器的inititializer setup_mail.rb. 但我想将...
例如,如果我有YAML文件 en: questions: new: 'New Question' other: recent: ...
我听说在RSpec中避免它,let,let !,指定,之前和主题是最佳做法. 关于让,让!之前,如果不使用这些,我该如...
我在Rails中使用MongoDB和mongo_mapper gem,项目足够大.有什么办法可以将数据从Mongoid迁移到 Postgres...