Reputation: 435
Is the sqlite3.Cursor.__iter__
method lazy? I.e. does it calculate all rows upfront and then yields them when iterated over, or does it calculate the rows only when I iterate over them? I am asking this because I am considering whether to add a LIMIT
clause to my SQL queries.
Upvotes: 2
Views: 743
Reputation: 180310
The SQLite C API is lazy; the sqlite3_step function computes the next result row on the fly.
As for Python's sqlite3
module, the source code shows that the pysqlite_cursor_iternext
function calls pysqlite_step
once.
Upvotes: 2