[Fixed]-Interpolate in SQL based on subgroup in django models

1👍

The ability to do this as one database call doesn’t exist in stock Django. 3rd party packages exist though: https://github.com/aykut/django-bulk-update

Example of how that package works:

rows = Model.objects.all()
for row in rows:
    # Modify rows as appropriate
    row.T_val = delta / (cnt -1) * row.sheet_num + min_tvc_of_subgroup
Model.objects.bulk_update(rows)

For datasets up to the 1,000,000 range, this should have reasonable performance. Most of the bottleneck in iterating through and .save()-ing each object is the overhead on a database call. The python part is reasonably fast. The above example has only two database calls so it will be perhaps an order of magnitude or two faster.

Leave a comment