2

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?

2
  • 4
    remove the header (column names) from your csv. It's trying to put the string product_id into an integer column now. Commented Sep 2, 2022 at 12:57
  • 1
    @VvdL right, worked now like a charm. Thanks! Commented Sep 2, 2022 at 13:01

1 Answer 1

2

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

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.