Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase max bulk_batch_size #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions sql_server/pyodbc/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ def bulk_batch_size(self, fields, objs):
are the fields going to be inserted in the batch, the objs contains
all the objects to be inserted.
"""
objs_len, fields_len, max_row_values = len(objs), len(fields), 1000
if (objs_len * fields_len) <= max_row_values:
size = objs_len
else:
size = max_row_values // fields_len
return size
fields_len = len(fields)
# MSSQL allows a query to have 2100 parameters but some parameters are
# taken up defining `NVARCHAR` parameters to store the query text and
# query parameters for the `sp_executesql` call. This should only take
# up 2 parameters but I've had this error when sending 2098 parameters.
max_query_params = 2050
# inserts are capped at 1000 rows. Other operations do not have this
# limit.
return min(1000, max_query_params // fields_len)

def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
Expand Down