• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8294
  • Last Modified:

postgres ERROR: extra data after last expected column

Hello,
I am attempting to import some csv files into existing tables in my Postgresql database.
Instead of easily copying the data into my tables I seem to be doing something wrong.
Each of the tables in the database have identical columns matching the headers of each of the csv files however the tables have extra columns which are not represented in these files.

The csv files resemble this:
"thing2","thing3","thing4"
"baskets,"lunches",""
"fish","","cakes"
etc

the tables resemble this:
"thing1" varchar;
"thing2" varchar;
"thing3" varchar;
"thing4" varchar;
"thing5" varchar;

ERROR:  extra data after last expected column
CONTEXT:  COPY mytable, line 2: ""

Obviously I just want to import the values in the csv file into the tables leaving the columns that I can't fill null or blank.

What am I doing wrong?
COPY "mytable" ("thing2","thing3") FROM "myfile.csv" WITH DELIMITER ',' CSV QUOTE AS '"' NULL AS ' ' CSV HEADER;

Open in new window

0
tyrrrr
Asked:
tyrrrr
1 Solution
 
earth man2Commented:
devdb=# COPY csvimport(thing2,thing3,thing4) FROM '/home/postgres/csvimport.cvs' CSV HEADER FORCE NOT NULL thing2,thing3,thing4;
COPY 2
devdb=# select * from csvimport;
 thing1 | thing2  | thing3  | thing4 | thing5
--------+---------+---------+--------+--------
        | baskets | lunches |        |
        | fish    |         | cakes  |
(2 rows)
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now