Sample Header Ad - 728x90

How do I import CSV UUID data into Postgres on the command line?

1 vote
1 answer
3066 views
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 by Dave (753 rep)
Dec 12, 2021, 12:58 AM
Last activity: Apr 28, 2025, 03:06 PM