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
1 Answer 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
-
that is add the keyword "header" after the keyword "csv"Jasen– Jasen2022年11月27日 01:58:29 +00:00Commented Nov 27, 2022 at 1:58
lang-sql