Difference between cursor loop and cursor.fetchall loop in string queries

Say I have the following code

cursor = connection.cursor()
cursor.execute(query)

after this point I want to iterate over the whole set of results.

What's the difference between

for row in cursor:
    print row[0]


for row in cursor.fetchall():
   print row[0]

I

I guess the first one uses the fetchone method.

1) First, a query is executed at each iteration. 2) does it use the fetchone method or the fetchall method 3) which is better for great results?

+3
source share
1 answer

The ability to iterate over the cursor is an optional extension defined by PEP 249 , and the exact semantics depend on the database adapter used.

+2
source

Source: https://habr.com/ru/post/1778253/


All Articles