Invalid input syntax when uploading a csv in pgadmin

Viewed 38

This is probably super simple yet i can't figure it out, sorry. I created a simple CSV dataset:

product_id,type,profit,revenue
1,Fruit,18,10
2,Vegetable,14,7
3,Electronics,15,29
4,Cosmetics,5,19
5,Cosmetics,4,21

and a respective table in pgAdmin:

CREATE TABLE dataset.products(
    product_id int PRIMARY KEY,
    type varchar,
    profit numeric,
    revenue numeric
)

then, used the Import/Export data button and uploaded the file. However, every time I do it, I get an error:

ERROR: invalid input syntax for type integer: "product_id"
CONTEXT: COPY products, line 1, column product_id: "product_id"

I tried different data types for this field: numeric, serial, int (spelled also integer), nothing will work. What am I doing wrong?

1 Answers

In case you receive many CSV files and want to avoid modifying the source file, the import/export data windows allows you to turn on/off the header.

Move the Header switch to the Yes position to include the table header with the data rows. If you include the table header, the first row of the file will contain the column names.

enter image description here

Related