postgresql 将 .csv 导入我的数据库时,为什么会得到“最后一个预期列之后的额外数据”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22458464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:21:29  来源:igfitidea点击:

Why do I get the "extra data after last expected column' when importing .csv into my database?

postgresqlcsv

提问by Azar_Javed

Ok, I've managed to solve the problem. I had comas on the problematic lines which was causing the script to not run. I had to go through each one to fix it, but it worked in the end. Thanks

好的,我已经设法解决了这个问题。我在有问题的线路上出现了昏迷,这导致脚本无法运行。我不得不逐一修复它,但它最终奏效了。谢谢

I created a table using

我创建了一个表

CREATE TABLE customers_transfer
(
  customer text,
  phone text,
  alt_phone text,
  fax text,
  street1 text,
  street2 text,
  city text,
  state text,
  zip text,
  email text,      
)
WITH (
  OIDS=FALSE

);

and I have a .csv file that matches it. But when I try running COPY customers_transfer FROM 'C:/customer_transfer.csv' DELIMITER ','I get this error. I've tried adding a single ',' to every last line but it still happens.

我有一个与之匹配的 .csv 文件。但是当我尝试运行时,出现COPY customers_transfer FROM 'C:/customer_transfer.csv' DELIMITER ','此错误。我试过在最后一行添加一个“,”,但它仍然发生。

Access America Transport,423.821.8044,,423.678.7782,"2515 East 43rd St, Suite B",,Chattanooga,TN,37407,[email protected]

回答by Bruno

it should be

它应该是

COPY customers_transfer FROM 'C:/customer_transfer.csv' CSV

the DELIMITER ',' makes it split the text "2515 East 43rd St, Suite B" into two columns

DELIMITER ',' 将文本“2515 East 43rd St, Suite B”分成两列