Invalid input syntax for type integer in postgresql

柔情痞子 提交于 2020-02-25 04:41:10

问题


I'm trying to import a .csv file to my postgresql DB. I created a table as follows:

CREATE TABLE accounts
(
    acc_id integer,
    acc_name text,
    website text,
    lat numeric,
    longe numeric,
    primary_poc text,
    sales_rep_id integer
)

Then I used the following command to import the .csv file

COPY accounts(acc_id,acc_name,website,lat,longe,primary_poc,sales_rep_id) 
FROM 'D:\accounts.csv' DELIMITER ';' CSV ;

And my .csv file contains the following:

1;Walmart;www.walmart.com;40.23849561;-75.10329704;Tamara Tuma;321500
2;Exxon Mobil;www.exxonmobil.com;41.16915630;-73.84937379;Sung Shields;321510
3;Apple;www.apple.com;42.29049481;-76.08400942;Jodee Lupo;321520

However, this doesn't work and the following message appear:

ERROR:  invalid input syntax for type integer: "1"
CONTEXT:  COPY accounts, line 1, column acc_id: "1"
SQL state: 22P02

回答1:


Maybe there is a BOM in the CSV?

  • hexdump the file, and inspect the first three characters
  • (and) use an editor to remove the BOM
  • (or) export again, without the BOM (there should be a checkmark, even in the Microsoft "software")


来源:https://stackoverflow.com/questions/60250167/invalid-input-syntax-for-type-integer-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!