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 ',';
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With