Bulk insert with expressions in update-fields

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

The work on #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.

1 Like

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.

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 . Perhaps you could review or test this code.

3 Likes

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.

2 Likes