Best strategy for bulk inserts where some violate unique constraint?

From: Denis Papathanasiou <denis(dot)papathanasiou(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Best strategy for bulk inserts where some violate unique constraint?
Date: 2013-11-05 20:14:31
Message-ID: CAEpnaGzfZ2kZgAx72xi6SwN1sfx8xb42VaFdh__9siPuQtAw5w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

I'm using Pyscopg2 to insert multiple rows at once, using a dictionary as
shown at the bottom of this page:
https://wiki.postgresql.org/wiki/Psycopg2_Tutorial

I notice that even if just one entry violates a table unique constraint (an
IntegrityError in psycopg2 parlance), the entire contents of the dictionary
do not get inserted into the table.

Is there any way to tell postgres: it's ok to reject individual entries
that may violate table unique constraints, but at the same time allow those
which do not?

It's too expensive for me to do the inserts one at a time where I could
just catch the psycopg2.IntegrityError.

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2013-11-05 23:31:13 Re: Best strategy for bulk inserts where some violate unique constraint?
Previous Message Damiano Albani 2013-11-01 18:11:45 Re: Understanding memory usage