postgres ERROR:  extra data after last expected column

Posted on 2009-04-16
Last Modified: 2012-05-06
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:

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

Question by:tyrrrr
    1 Comment
    LVL 22

    Accepted Solution

    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)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now