“extra data after last expected column” while trying to import a csv file into postgresql

我的未来我决定 提交于 2019-11-30 10:46:07
Mladen Uzelac

Now you have 7 fields.

You need to map those 6 fields from the CSV into 6 fields into the table.

You cannot map only 3 fields from csv when you have it 6 like you do in:

\COPY agency (agency_name, agency_url, agency_timezone) FROM 'myFile.txt' CSV HEADER DELIMITER ',';

All fields from the csv file need to to be mapped in the copy from command.

And since you defined csv , delimiter is default, you don't need to put it.

Not sure this counts as an answer, but I just hit this with a bunch of CSV files, and found that simply opening them in Excel and re-saving them with no changes made the error go away. IOTW there is possibly some incorrect formatting in the source file that Excel is able to clean up automatically.

Mladen Uzelac

I tried your example and it works fine but ....

your command from the psql command line is missing \

database=#  \COPY agency FROM 'myFile.txt' CSV HEADER DELIMITER ',';

And next time please include DDL

I created DDL from the csv headers

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