django-postgres-extra
django-postgres-extra copied to clipboard
Exclude conflict_target fields from update fields
_get_upsert_fields
should not add fields in self.conflict_target
in the update_fields
If we are "on conflict" then we know that the conflict_target
columns already contains the value we wanted to insert, there is no need to update them with the same value
FYI, from a database point of view, this is not a silly optimization : conflict_target will always contain indexed fields, and doing an update on these fields will thus prevent an HOT update from happening. Not having this optimization will force the use of the built-in suppress_redundant_updates_trigger https://www.postgresql.org/docs/10/functions-trigger.html on the DB side.
At the face of this sounds very simple, but if it was I guess someone would have solved it already. Is there some hidden complexity that means update_fields = [field for field in update_fields if field not in conflict_targets]
(pseudo-ish-code, the types don't match up directly) doesn't work?