django-postgres-copy icon indicating copy to clipboard operation
django-postgres-copy copied to clipboard

Add upsert functionality

Open geoffrey-eisenbarth opened this issue 4 months ago • 0 comments

I've updated my older PR #156 to align with the recent psycopg changes. Where possible, I have utilized the approach taken by Django in queryset.bulk_create(), which supports upsert (see docs).

At the moment, specifying update_conflicts=True also requires explicitly setting drop_indexes=False and drop_constraints=False (since they are required by PostgreSQL to locate conflicting rows). This leads to a few options:

  1. Keep as is and require the user to be explicit in overriding the drop_indexes and drop_constraints defaults.
  2. Let update_conflicts=True override and set drop_indexes and drop_constraints to False.
  3. Change the default values of drop_indexes and drop_constraints, as discussed in #117.

Despite my comments in #117, I now have no preference among those options and would be happy to have it implemented any such way.

I'd be happy to answer any questions or implement any requested changes.

Merging this PR would close #91, #117 (possibly as "won't fix"), #122, and #168.

geoffrey-eisenbarth avatar Aug 13 '25 18:08 geoffrey-eisenbarth