-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bulk_update_or_create(model_instances) or bulk_update(model_instances, upsert=True)? #49
Comments
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? |
@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 |
I need this feature. Any news? |
I think it's possible to add this feature. I would call it But even if we implement this function here, we will also need to know which instances already exist (performing an additional query). Seems reasonable for you? Any better approach? |
It's seems reasonable. Although both postgres and mysql now suport bulk upsert: |
I do agree with @arnau126, Any update about this feature. |
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. |
For my current job we need bulk upsert of records, and I'm thinking of forking your package and implementing bulk_upsert myself. If/when I do that, I'd like to do it in the manner that's most likely to be accepted into your project, so as not to maintain an independent fork.
Which syntax do you prefer?
For now I'd only make my changes compatible with Postgres 9.5+, because that's what we're using and because I'm relatively new at this niche.
Any other advice/comment?
The text was updated successfully, but these errors were encountered: