If I recall correctly, MySQL doesn't offer a way to specify on which index you want to do the conflict resolution. This leads to problems - the upsert might affect the wrong row if there are multiple unique indexes on the table.
PostgreSQL's version of upsert has a problem, too. It doesn't offer a direct way to know if the result of the upsert was an insert or update, but Django needs that knowledge, at least for save(). Maybe there is a way (the oid return value seems promising). For get_or_create and update_or_create the problem is that the user is free to offer any condition to be used for matching, but PostgreSQL limits the upsert matching to columns in unique index. So, we can use upsert only for unique index cases. The save() operation matches the semantics of upsert exactly - maybe we could use upsert there? - Anssi On Sunday, January 10, 2016, Cristiano Coelho <cristianocc...@gmail.com> wrote: > I agree! Also, does this already happen for the MySQL backend? MySQL has > the insert on conflict update, that could work the same way. > However, if I'm not wrong, the docs states that the above methods have a > race condition (obvious since right now it does two operations), but if the > code would actually use native database operations, the race conditions > might be gone for those cases, so that should probably be documented as > well. > > El viernes, 8 de enero de 2016, 21:13:26 (UTC-3), bliy...@rentlytics.com > <javascript:_e(%7B%7D,'cvml','bliy...@rentlytics.com');> escribió: >> >> Hey Guys, >> >> Postgres 9.5 has added the functionality for UPSERT aka update or >> insert. Any interest in aligning UPSERT on the db layer with the >> get_or_create or update_or_create functionality in django? Sounds like my >> company would be interested in doing the work if the PR will get the >> traction. >> >> -Ben >> > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com > <javascript:_e(%7B%7D,'cvml','django-developers%2bunsubscr...@googlegroups.com');> > . > To post to this group, send email to django-developers@googlegroups.com > <javascript:_e(%7B%7D,'cvml','django-developers@googlegroups.com');>. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/ae38ba8e-3e79-47fb-92b9-dd305176c58e%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/ae38ba8e-3e79-47fb-92b9-dd305176c58e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CALMtK1Gub-uL3AdgFSxQkdUNNe_Q47%3D7O%3DZ4qsW3Exwjhkd4ZA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.