Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: extra data after last expected column on postgresql

When I import csv file I see the this error

ERROR: extra data after last expected column SQL state: 22P04 Context: COPY everyhighschool, line 1: "B100005528,서울특별시,구암고등학교,구암고등학교,,,,,"

My table

CREATE table everyhighschool(
schoolcode varchar(10),
region varchar(20),
shortschoolname varchar(30),
schoolname varchar(30))

My copy code

COPY everyhighschool(schoolcode, region, shortschoolname, schoolname)FROM 'C:\Users\Administrator\Desktop\code.csv' WITH DELIMITER ',';
like image 962
MinGi Kim Avatar asked Oct 24 '25 07:10

MinGi Kim


2 Answers

Well, it's a pretty clear error message if you ask me.. your code told the database to expect 4 columns of data and then you provided a file with 9 columns of data..

Just because there is nothing between the last 5 commas doesn't mean it isn't data!

Clean up the file in a text editor and try again

like image 177
Caius Jard Avatar answered Oct 25 '25 21:10

Caius Jard


For what it's worth, this has vexed me more than once, and it's a trailing comma that has gotten me over and over.

So a line that looks like this:

one,two,three,four,

Has FIVE columns, not four:

one
two
three
four
<null>

Hope this helps anyone who is going nuts because they paste the data into Excel and it lines up perfectly.

like image 40
Hambone Avatar answered Oct 25 '25 19:10

Hambone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!