Postgresql – Postgres COPY with on conflict ignore – possible

copypostgresqlpostgresql-12

I want to add on conflict ignore to the Postgres copy command.
I know I can copy the data to a table without unique index /primary key and then use insert with the on conflict syntax.
But I wanted to know if this is possible directly from COPY?

Best Answer

No. Maybe in some future version. Now about the best you can do is use file_fdw to map the file in as a foreign table, and then INSERT INTO...SELECT...ON CONFLICT DO NOTHING