【发布时间】:2016-02-25 19:12:07
【问题描述】:
这是我第一次将 CSV 文件复制到我的 Rails 4 Heroku 应用程序。
执行以下步骤会收到错误消息。
从命令行收到的消息:
ERROR: invalid input syntax for integer: "Employee personnel files"
CONTEXT: COPY articles, line 29, column id: "Employee personnel files"
使用这个命令:
PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy articles FROM 'lib/articles' WITH CSV HEADER;"
这是 CSV 文件的 sn-p:
line 1 "Title","Body"
line 2 "Employee personnel files","
As an HR professional you are no stranger to paperwork. It seems that for every employment action - applying, interviewing, hiring, disciplining, on and on - there is a specific form that needs to be filled out. Making sure you complete the paperwork properly is only half the battle though. Once you finish completing a form, you are faced with a whole new issue: what to do with it. Being the smarty that you are, you know that proper documentation is key in protecting your company in the unfortunate case of a lawsuit, but knowing what needs to be kept where and for how long and who can see it can be kind of tricky. Let's take a minute to go over the basics.
...
line 29 Looking for more sample polices and important forms? Click here to gain access."
关于缺少什么的任何建议?
【问题讨论】:
-
那不是 csv。 csv 每行有一条记录。您有一条记录分布在多行中。
-
你建议使用什么?
-
csv 是其他所有格式都失败时的最后手段,即使那样你也应该三思而后行。几乎可以使用其他任何东西,例如xml - 它有处理内部数据转义的明确规定,否则会导致无效的 xml 文档。
-
正如 Marc 所说,它应该是每行一条记录。如果您打算使用 COPY 命令,您还必须记住创建一个没有 ID 列的表,否则您必须在每行中放置一个唯一的序号值以适应复制时的 ID 列。
-
@MarcB 如何导入 xml 文件?我从本地机器上的 CSV 开始,效果很好,使用 /lib/tasks/import.rake 文件导入文章数据。我假设这不是 Rails 生产站点的工作方式?
标签: ruby-on-rails postgresql csv heroku