1

I'm fairly new to postgres. I am trying to copy over a file from my computer to a postgres server. I first initialize the table with

CREATE TABLE coredb (
id text, lng numeric(6,4), lat numeric(6,4),
score1 numeric(5,4), score2 numeric(5,4));

And my CSV looks like this:

     ID       lng      lat    score1   score2
      1     -72.298  43.218   0.561     0.894
      2     -72.298  43.218   0.472     0.970
      3     -72.285  43.250   0.322     0.959
      4     -72.285  43.250   0.370     0.934
      5     -72.325  43.173   0.099     0.976
      6     -72.325  43.173   0.099     0.985

However, when I try to copy the CSV over, I get the following error

COPY coredb FROM '/home/usr/Documents/filefordb.csv' DELIMITER ',' CSV;
ERROR:  invalid input syntax for type numeric: "lng"
CONTEXT:  COPY nhcore, line 1, column lng: "lng"

Oddly enough the csv imports just fine when I set the CREATE TABLE parameters to text for all the columns. Could someone explain why this is happening? I am using psql 9.4.1

1
  • Are you sure your CSV looks like that? That has no commas in it. It looks like you'd need to change your DELIMITER ',' to something better and use the WITH HEADER true option Commented Apr 23, 2015 at 18:41

1 Answer 1

2

You have to use HEADER true to tell COPY to skip the header line.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.