SectorLabs / django-postgres-extra

Bringing all of PostgreSQL's awesomeness to Django.
MIT License
695 stars 96 forks source link

support for update_values paramter on on_onflict() method. #234

Closed anupsingh3292 closed 8 months ago

anupsingh3292 commented 9 months ago

The doc has an example of the update_values parameter on the on_conflict() method, but the actual implementation is not done yet. please add it.

the doc Update values Optionally, the fields to update can be overriden. The default is to update the same fields that were specified in the rows to insert.

Refer to the insert values using the psqlextra.expressions.ExcludedCol expression which translates to PostgreSQL’s EXCLUDED. expression. All expressions and features that can be used with Django’s update() can be used here.

Warning Specifying an empty update_values ({}) will transform the query into NOTHING. Only None makes the default behaviour kick in of updating all fields that were specified.

from django.db.models import F

from psqlextra.expressions import ExcludedCol

( MyModel .objects .on_conflict( ['name'], ConflictAction.UPDATE, update_values=dict( name=ExcludedCol('name'), count=F('count') + 1, ), ) .insert( name='henk', count=0, ) )

chazanas commented 8 months ago

I'm having the same issue

anupsingh3292 commented 8 months ago

I'm having the same issue

hey, it has been implemented. install or upgrade to version django-postgres-extra==2.0.9rc8