cursor.fetchall() vs list(cursor) in Python -


both methods return list of returned items of query, did miss here? or have identical usages indeed? differences performance wise?

if using default cursor, mysqldb.cursors.cursor, the entire result set stored on client side (i.e. in python list) time cursor.execute() completed.

therefore, if use

for row in cursor: 

you not getting reduction in memory footprint. entire result set has been stored in list (see self._rows in mysqldb/cursors.py).

however, if use sscursor or ssdictcursor:

import mysqldb import mysqldb.cursors cursors  conn = mysqldb.connect(..., cursorclass=cursors.sscursor) 

then the result set stored in server, mysqld. can write

cursor = conn.cursor() cursor.execute('select * hugetable') row in cursor:     print(row) 

and rows fetched one-by-one server, not requiring python build huge list of tuples first, , saving on memory.

otherwise, others have stated, cursor.fetchall() , list(cursor) same.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -