2

I've successfully created the following table:

CREATE TABLE tampadocs (
fname varchar(255),
lname varchar(255),
pracName varchar(255),
address varchar(255),
city varchar(255),
state varchar(255),
zip varchar(255),
spec varchar(255),
phone varchar(255),
totalMD integer,
avgPt integer,
mdName varchar(255),
notes varchar(255));

Then run the following to import data from a CSV to the table:

COPY tampadocs 
FROM 'C:\Users\bam\Desktop\tampadocs.csv' DELIMITERS ',' CSV;

I receive the following error:

ERROR:  invalid input syntax for integer: "Total MDs"
CONTEXT:  COPY tampadocs, line 1, column totalmd: "Total MDs"

I've looked at each value in the Total MDs column but they are just numbers, so I'm not sure what I'm missing. Any help would be greatly appreciated!

1
  • We can't help with the syntax questions if you don't show us what actually is causing that error. Give a sample of the CSV. Commented Apr 17, 2016 at 23:22

1 Answer 1

1

Sounds like your file 'tampadocs.csv' has a header line. Can you check on that? The copy syntax you're using is assuming there's only data in the file.

If there's a header line in your file, you can try the following:

COPY tampadocs
  FROM 'C:\Users\bam\Desktop\tampadocs.csv'
  WITH (FORMAT CSV, DELIMITER ',', HEADER);

That lets the copy statement know to expect a header line in the file. The full syntax for COPY is available here.

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

1 Comment

It was the header, thanks a bunch. Next time I will provide more information.