1 year ago
#330792
Madan
How to use upsert command in django for bulkupdate?
I need to update 1000's of rows each with differant values in timescale db.
I found bulk update to do so.
list = ModelClass.objects.filter(name = 'bar')
obj_to_be_update = []
for obj in list:
obj.name = "Dear "+obj.name
obj_to_be_update.append(obj)
ModelClass.objects.bulk_update(obj_to_be_update, ['name'], batch_size=1000)
This takes alot of time to update and even atomic transaction took alot time to update in the db.
Instead found upsert for timescale db which does execution faster. Any idea how to do it in django.
https://docs.timescale.com/timescaledb/latest/how-to-guides/write-data/upsert/#upsert-functionality
python
django
upsert
timescaledb
0 Answers
Your Answer