# Bulk insert with expressions in update-fields

**URL:** <https://forum.djangoproject.com/t/bulk-insert-with-expressions-in-update-fields/30272>\
**Category:** ORM\
**Created:** [April 17, 2024, 3:40pm UTC](https://forum.djangoproject.com/t/bulk-insert-with-expressions-in-update-fields/30272 "2024-04-17T15:40:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sevdog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sevdog/32/20692_2.png) [@sevdog](https://forum.djangoproject.com/u/sevdog)\
**Post date:** [April 17, 2024, 3:40pm UTC](https://forum.djangoproject.com/t/bulk-insert-with-expressions-in-update-fields/30272/1 "2024-04-17T15:40:17Z")

</div>

On various DBMS it is supported to write complex expressions to be used in the insert/update ON CONFLICT clause.

The work on [#31685](https://code.djangoproject.com/ticket/31685) is great, but the lack of complex conflict handling is a big disadvantage when interacting with a database which offers this feature

It would be great to write in the ORM: “on conflict increase the value of column X by Y” or “on conflict concat the previous value with the new one”.

It will also be very good to allow using the `WHERE` clause in the `ON CONFLICT` statement to allow a more fine handling of conflicts on the database side.

Is this feature on roadmap or is there a way to achieve this without using a third party app.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 17, 2024, 4:02pm UTC](https://forum.djangoproject.com/t/bulk-insert-with-expressions-in-update-fields/30272/2 "2024-04-17T16:02:37Z")

</div>

Welcome. Django doesn’t have a strict roadmap, all contributions come from volunteers. If you‘d like to see this feature, you could start by proposing syntax and asking for feedback here on the forum. If you’re feeling brave, you can also try working on the code, see [the contributing docs](https://docs.djangoproject.com/en/dev/internals/contributing/).

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 17, 2024, 8:12pm UTC](https://forum.djangoproject.com/t/bulk-insert-with-expressions-in-update-fields/30272/3 "2024-04-17T20:12:23Z")

</div>

> [@sevdog](#):
>
> It will also be very good to allow using the `WHERE` clause in the `ON CONFLICT` statement to allow a more fine handling of conflicts on the database side.

This is being worked on: [Added #34277 -- Add Conditional WHERE Clause to bulk\_create for SQLite and PostgreSQL by HamaBarhamou · Pull Request #17515 · django/django · GitHub](https://github.com/django/django/pull/17515) . Perhaps you could review or test this code.

---

<div class="post-metadata">

**Author:** ![sevdog](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sevdog/32/20692_2.png) [@sevdog](https://forum.djangoproject.com/u/sevdog)\
**Post date:** [April 18, 2024, 8:11am UTC](https://forum.djangoproject.com/t/bulk-insert-with-expressions-in-update-fields/30272/4 "2024-04-18T08:11:55Z")

</div>

The work on that PR sure has some overlapping with what I am looking for, like the `Excluded` expression. I will keep an eye on it and wait for it to be merged before starting to think about how it could be implemented what I would like to have and opening a related issue.
