HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Postgres COPY with on conflict ignore - possible?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
ignorepostgreswithpossibleconflictcopy

Problem

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?

Solution

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

Context

StackExchange Database Administrators Q#283479, answer score: 8

Revisions (0)

No revisions yet.