2

I am trying to import a .csv file into a postgresql database. I am using pgadmin III for that on a win7 machine.

My query looks like that:

\COPY pop_grid(GRID_ID, POP_TOT, YEAR, METHD_CL, CNTR_CODE, DATA_SRC) from 'C:\...\popgrid.csv' DELIMITERS ',' CSV;

The data inside the .csv looks like that:

1kmN5142E2862 2 2006 D IS AIT
1kmN5141E2862 13 2006 D IS AIT

My table:

CREATE TABLE pop_grid 
(
 GRID_ID text PRIMARY KEY,
 POP_TOT int NOT NULL,
 YEAR date NOT NULL,
 METHD_CL varchar(2) NOT NULL,
 CNTR_CODE varchar(32) NOT NULL,
 DATA_SRC varchar(4) NOT NULL
);

Why do I get this error?

ERROR: Missing data for column "pop_tot"
CONTEXT: COPY pop_grid, Row 1: "1kmN5142E2862;2;2006;D;IS;AIT"

There is nothing missing?

asked Jun 5, 2012 at 9:44

1 Answer 1

4

You tell the COPY command to look for commas as delimiters (DELIMITERS ','), but there are no commas in your CSV. Use the 'text' format instead (it's the default, so you don't have to specify it) and do not specify a delimiter:

The default is a tab character in text format.

(source)

answered Jun 5, 2012 at 10:45
1
  • yeah, that was it! I should really at least try to understand what I'm copying :) The delimiters was actually ';' instead of ','. They were missing in my question, because I copied it out of excel. Commented Jun 5, 2012 at 11:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.