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?

1
  • I guess you want header false or something.
    – mustaccio
    Dec 12, 2021 at 1:10

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.

1
  • that is add the keyword "header" after the keyword "csv"
    – Jasen
    Nov 27, 2022 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.