generated from opensafely-core/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
psycopg can only send 65535 parameters in one go. Each values dict is currently 5 items, which means we end up with 10 parameters (name+value). Batching at 10k rows keeps the number of parameters under the limit.
- Loading branch information
Showing
2 changed files
with
30 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import itertools | ||
|
||
|
||
def batched(iterable, n): | ||
""" | ||
Backport of 3.12's itertools.batched | ||
https://docs.python.org/3/library/itertools.html#itertools.batched | ||
batched('ABCDEFG', 3) --> ABC DEF G | ||
""" | ||
it = iter(iterable) | ||
while batch := tuple(itertools.islice(it, n)): | ||
yield batch |