开发者

difference between looping a cursor and looping cursor.fetchall in row queries

开发者 https://www.devze.com 2023-01-28 20:46 出处:网络
Let\'s say I have following code cursor = connection.cursor() cursor.execute(query) after that point I want to loop over all the resultset.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消