I have something like this:
# pseudo code
while True:
result = make_request_for_data(my_http_request)
query = "INSERT INTO my_table (col1, col2) VALUES (%s, %s);"
for data in result:
cursor.execute(query, data)
connection.commit() # should this be inside while loop or outside?
if result is None: # some breaking mechanism
break
cursor.close()
connection.close()
Are there performance benefits and why? I will do some timings but wanted to know why one is better than the other, if that is the case.