Reputation: 195
def fast_execute():
mydb = pyodbc.connect(connection_string,autocommit=True)
mycursor = mydb.cursor()
mycursor.execute("use care_new")
mycursor.execute("truncate dummytable")
print('executed 1')
mycursor.fast_executemany = True
print('executed 2')
query = "insert into dummytable(ID, Name) values(?,?)"
value = [((f'{i}'),(f'Names{str(i)}'),) for i in range(10000)]
t0 = time.time()
print('executed 3')
mycursor.executemany(query, value)
print('executed 4')
print(f'{time.time() - t0:.1f} seconds for fast execute many')
mydb.close()
Output
executed 1
executed 2
executed 3
I cant figure out why program wont execute mycursor.executemany(query,value)
and post steps.
If i comment out mycursor.fast_executemany = True
line, it works fine. But that takes around 45 secs since Im dealing with 10000 records.
Am i missing something here?
Upvotes: 0
Views: 201
Reputation: 782130
You have too many levels of nesting in your list of tuples. Each row being inserted is just a normal tuple of 2 elements.
There's also no need to format the ID as a string.
value = [(i, f'Names{str(i)}') for i in range(10000)]
Upvotes: 0