开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜