Ruby 我从csv文件将数据导入postgresql时出错,文件名为“sequel”`
我正试图将数据从csv文件导入postgresql,如下所示Ruby 我从csv文件将数据导入postgresql时出错,文件名为“sequel”`,ruby,postgresql,sequel,Ruby,Postgresql,Sequel,我正试图将数据从csv文件导入postgresql,如下所示 csv = CSV.open(path, { col_sep: ',', headers: :first_row }) MatchDB.db.copy_into(:property, data: csv, format: :csv ) 但我犯了这样的错误 TypeError: wrong argument type CSV::Row (expected String) 有人知道如何解决这个问题吗?正如您在中所看到的,该方
csv = CSV.open(path, { col_sep: ',', headers: :first_row })
MatchDB.db.copy_into(:property,
data: csv,
format: :csv
)
但我犯了这样的错误
TypeError: wrong argument type CSV::Row (expected String)
有人知道如何解决这个问题吗?正如您在中所看到的,该方法需要一个字符串,其中列由逗号分隔,行由行分隔符分隔\n
您正试图传递一个ruby internalCSV
表示,它[一般来说]是一个数组数组。我不是rubyCSV
的大师,但要从中提取适当的字符串,可以使用:
csv.map { |row| row.join ',' }.join "\n"
总结如下:
csv = CSV.open(path, { col_sep: ',', headers: :first_row })
MatchDB.db.copy_into(:property,
data: csv.map { |row| row.join ',' }.join "\n",
format: :csv
)
请在
MatchDB
上链接一个文档好吗?它只是连接到DB.def self.DB@@DB | |=Sequel.connect(适配器:'postgres',数据库:'matches',用户:'master',主机:'localhost',密码:'123456')结束