Opened 10 years ago
Last modified 3 years ago
#23646 closed New feature
query set sql update to change different values by different keys — at Version 1
Reported by: | Brillgen Developers | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Tom Forbes | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Database backends like Postgresql support doing multiple value update for the same field in different rows using a single update query. Please see this sample below:
http://stackoverflow.com/questions/18797608/update-multiple-rows-in-same-query-using-postgresql
Example:
Currently:
Books.objects.all().update(price=10)
Proposed (syntax can vary):
Books.objects.all().update({'pk': 1, 'price': 10}, {'pk': 2, 'price': 25}])
Idea is to do it in sql for performance reasons but still use the ORM and not use a raw database connection.
However, such an interface is not exposed via the Django ORM. Would this be accepted as a patch? if so, would a list dictionary with the various fields:values to be updated be a good way to provide the input to ORM