Python3 – Is there a way to iterate row by row over a very large SQlite table without loading the entire table into local memory?

cursor.fetchall() fetches all results into a list first.

Instead, you can iterate over the cursor itself:

c.execute('SELECT * FROM big_table') 
for row in c:
    # do_stuff_with_row

This produces rows as needed, rather than load them all first.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)