Skip to content

Increasing buffer size for fast_executemany = True #1356

Discussion options

You must be logged in to vote

I dunno, this works for me:

import pyodbc

cnxn = pyodbc.connect(
    "DSN=msodbcsql18_199;UID=scott;PWD=tiger^5HHH",
    autocommit=True,
)
crsr = cnxn.cursor()

crsr.execute("DROP TABLE IF EXISTS disc_1356")
crsr.execute(
    "CREATE TABLE disc_1356 (id int IDENTITY PRIMARY KEY, geog_col geography)"
)

num_points = 1000
pts = [(0.000, 0.001 * x) for x in range(num_points)]
s = ", ".join([f"{p[0]:0.3f} {p[1]:0.3f}" for p in pts])
print(len(s))  # 12998

crsr.fast_executemany = True
crsr.setinputsizes([(pyodbc.SQL_WVARCHAR, 0)])
crsr.executemany(
    "INSERT INTO disc_1356 (geog_col) VALUES (geography::STGeomFromText(?, 4326))",
    [(f"LINESTRING({s})",) for x in range(2)],
)

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@CarlaFernandez
Comment options

Comment options

You must be logged in to vote
1 reply
@CarlaFernandez
Comment options

Comment options

You must be logged in to vote
3 replies
@CarlaFernandez
Comment options

@gordthompson
Comment options

Answer selected by CarlaFernandez
@CarlaFernandez
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants