1

I'm using PostGres 10. I have this table

> \d myapp_currencyprice;
 Table "public.myapp_currencyprice"
 Column | Type | Modifiers 
--------------------+--------------------------+-----------
 id | uuid | not null
 price | double precision | not null
 created | timestamp with time zone | not null
 currency_id | uuid | not null

I have a CSV of data, which looks like

id,price,created,currency_id
fa9944a6-f622-499c-89b8-42534a541307,59451.41,2021年11月20日 15:56:00-05,3965e495-d5a5-41ec-83fc-359545ca2716
13013751-d84a-441f-a19a-3c7b50c557d0,59474.17,2021年11月20日 15:58:00-05,3965e495-d5a5-41ec-83fc-359545ca2716

but when I try and import the data on the command line, I get this error

> PGPASSWORD=$DB_PASS psql -U $DB_USER -d $DB_NAME -c "\copy myapp_currencyprice FROM '/tmp/prices.csv' delimiter ',' csv"
ERROR: invalid input syntax for uuid: "id"
CONTEXT: COPY myapp_currencyprice, line 1, column id: "id"

what's the right way to import data from a CSV into a PostGres table?

asked Dec 12, 2021 at 0:58
0

1 Answer 1

1

As the error message says, the string "id" is not proper to be a UUID.

Either remove the header line from the file, or tell \copy that the file has a header line.

answered Dec 12, 2021 at 18:04
1
  • that is add the keyword "header" after the keyword "csv" Commented Nov 27, 2022 at 1:58

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.