GithubHelp home page GithubHelp logo

Comments (9)

arnau126 avatar arnau126 commented on July 28, 2024 1

I think it's possible to add this feature. I would call it bulk_update_or_create because django already has a update_or_create for single instances.

But even if we implement this function here, we will also need to know which instances already exist (performing an additional query). bulk_update_or_create will actually split the list of instances and call bulk_create and bulk_update separately. So each batch will perform 3 queries.

Seems reasonable for you? Any better approach?

from django-bulk-update.

aykut avatar aykut commented on July 28, 2024

Hi,

I'm not sure it is a good idea to include bulk_create into this project. Django already has built-in bulk_create method. Why not separate the objects into create and update, then use bulk_create and bulk_update explicitly?

from django-bulk-update.

ckcollab avatar ckcollab commented on July 28, 2024

@candeira I'm way into that! I could use this on my project, for sure.

@aykut bulk_update_or_create is different from bulk_create?

from django-bulk-update.

phlax avatar phlax commented on July 28, 2024

@candeira @aykut @ckcollab this would be amazingly helpful

from django-bulk-update.

phlax avatar phlax commented on July 28, 2024

@aykut the problem with doing bulk_create is that you need to know in advance which ones exist already - so requires an additional query i think

from django-bulk-update.

mehdipourfar avatar mehdipourfar commented on July 28, 2024

I need this feature. Any news?

from django-bulk-update.

mehdipourfar avatar mehdipourfar commented on July 28, 2024

It's seems reasonable. Although both postgres and mysql now suport bulk upsert:
https://stackoverflow.com/questions/34514457/bulk-insert-update-if-on-conflict-bulk-upsert-on-postgres
https://stackoverflow.com/questions/6286452/mysql-bulk-insert-or-update

from django-bulk-update.

abdulwahid24 avatar abdulwahid24 commented on July 28, 2024

I do agree with @arnau126, Any update about this feature.

from django-bulk-update.

Bartvds avatar Bartvds commented on July 28, 2024

The 3 query approach is a race condition; unless you can be sure your program is the only one writing to that table you'll have to add retry logic around the transaction (as records can get added and removed between your read and create step).

SQL level UPSERT is the way to go for atomic single query update/create.

from django-bulk-update.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.