#35793: Add support for atomic upserts
-------------------------------------+-------------------------------------
Reporter: Storm Heg | Owner:
| YashRaj1506
Type: New feature | Status: assigned
Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Take Weiland):
I just found this ticket after I already made
https://code.djangoproject.com/ticket/36567
I am copying the relevant info here.
- All supported DBs (all except Oracle, for which `update_conflicts` is
not implemented) support referring to the values that were about to be
inserted.
- PostgreSQL and SQLite explicitly state support for referring to the row
that is conflicting and that will be updated
(www.postgresql.org/docs/current/sql-insert.html,
https://sqlite.org/lang_upsert.html)
- MySQL does not state such support, however their examples show it being
done (`ON DUPLICATE KEY UPDATE c=c+1;` from
https://dev.mysql.com/doc/refman/9.4/en/insert-on-duplicate.html)
- MariaDB does not state such support, however considering it started from
MySQL I would be surprised if it is not supported.
My API bikeshedding was something like this:
{{{
MyModel.objects.bulk_create(
objs,
update_conflicts=True,
update_fields={
'field_b': Coalesce(F('field_b'), Inserted('field_b'))
}
)
}}}
I use `Inserted` here, but it could just as well be `Excluded`.
--
Ticket URL: <https://code.djangoproject.com/ticket/35793#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070198cdefb97c-7ef88f39-604a-4905-9958-38b4b3beadf4-000000%40eu-central-1.amazonses.com.