Inserting an array using Sequel gem in PostgreSQL

前端 未结 3 878
星月不相逢
星月不相逢 2020-12-12 03:54

i created a table with the following schema in code

DB.create_table :Pokemon do
  primary_key :id
  String :first_name
  String :last_name
  String :email
           


        
相关标签:
3条回答
  • 2020-12-12 03:59

    You need to use Sequel's pg_array extension, see http://sequel.rubyforge.org/rdoc-plugins/files/lib/sequel/extensions/pg_array_rb.html

    0 讨论(0)
  • 2020-12-12 04:07

    As the error says, just cast the Array expression to a string, like so:

    pokes.insert(:first_name => 'abcd' ,:last_name => 'mehandiratta', :offering => off.to_s , :needs =>  nee.to_s)
    
    0 讨论(0)
  • 2020-12-12 04:18

    In your database config:

    DB.extension :pg_array

    Then just convert each array to type PGArray:

    pokes.insert(:first_name => 'abcd' ,:last_name => 'mehandiratta', :offering => Sequel.pg_array(off) , :needs => Sequel.pg_array(nee))

    @Jeremy Evans' answer provides a link to the docs which include a more succinct way to do it if using the core-extensions extension.

    0 讨论(0)
提交回复
热议问题