difference between looping a cursor and looping cursor.fetchall in row queries
Let's say I have following code
cursor = connection.cursor()
cursor.execute(query)
after that point I want to loop over all the resultset.
what is the difference between
for row in cursor:
print row[0]
for row in cursor.fetchall():
print row[0]
I
am guessing that first one is using fetchone method.
1) Is first on开发者_JAVA技巧e runs a query on every iteration. 2) does it use fetchone method or fetchall method 3) which is better for big resultset?
The ability to iterate over a cursor is an optional extension as defined by PEP 249, and the exact semantics depend upon the database adapter being used.
精彩评论