- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsHello,
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?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: earthman2Posted on 2009-04-16 at 14:39:24ID: 24162930
devdb=# COPY csvimport(thing2,thing3,th ing4) 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)