Skip to content

Instantly share code, notes, and snippets.

@sebabouche
Created November 14, 2017 22:00
Show Gist options
  • Save sebabouche/e44602927c9f6bdb3dd32ea359a301ad to your computer and use it in GitHub Desktop.
Save sebabouche/e44602927c9f6bdb3dd32ea359a301ad to your computer and use it in GitHub Desktop.
Batch update a big query based on total and batch quantity
import math
# from b_estimates.models import BEstimate
#
# be_list = BEstimate.objects.all()
be_list = list(range(4934))
# total_count = be_list.count()
total_count = 4934
batch_count = 500
iterations = math.ceil(total_count / batch_count)
for i in list(range(iterations)):
start = i * batch_count
if (i == iterations - 1):
end = start + total_count % batch_count
else:
end = (i + 1) * batch_count - 1
print(start, end)
# batch = be_list[i * batch_count]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment