Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (12.7k points)
The two methods return a list of the returned things of the inquiry, did I miss something here?

Or on the other hand, they have indistinguishable uses undoubtedly?

Are any differences in performance-wise?

1 Answer

0 votes
by (26.4k points)

On the off chance that you are utilizing the default cursor, a MySQLdb.cursors.Cursor, the whole outcome set will be put away on the customer side (for example in a Python list) when the cursor.execute() is finished. 

Even if you utilize,

for row in cursor:

you won't get any decrease in memory impression. The whole outcome set has effectively been put away in a list (See self._rows in MySQLdb/

In case, if you utilize SSCursor or SSDictCursor:

import MySQLdb

import MySQLdb.cursors as cursors

conn = MySQLdb.connect(..., cursorclass=cursors.SSCursor)

Then, the result set will be stored in the mysqld (Server). Now, You can compose

cursor = conn.cursor()

cursor.execute('SELECT * FROM HUGETABLE')

for row in cursor:


also, the rows will be brought individually from the server, in this way not expecting Python to construct a tremendous list of tuples first, and hence saving money on memory. 

Something else, as others have effectively expressed, cursor.fetchall() and list(cursor) are basically something very similar.

Wanna become a Python expert? Come and join the python certification course and get certified.

Related questions

0 votes
1 answer
asked Mar 6 in Python by laddulakshana (12.7k points)
+3 votes
2 answers
0 votes
1 answer
asked Jul 29, 2019 in Python by Rajesh Malhotra (19.9k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.7k users

Browse Categories