sql - When did sqlalchemy execute the query? -
as i've start learning use sqlalchemy recently, result of following code make me confused when sqlalchemy execute query:
query = db.session.query(mytable) query = query.filter(...) query = query.limit(...) query = query.offset(...) records = query #records=query.all() r in records: #do
note line
records = query #records=query.all()
seems brings same correct result(stored in variable "records") when using "query" , "query.all()", wonder when query executed?
if executed during first line "db.session.query(mytable)", result set may large @ point; if during fifth line "records = query", how happen there's no function call @ all?
in example, query gets executed upon for r in records
. accessing query object via iterator triggers execution. (normally, compiled select
statement)
up until time, query built (via filter
, limit
etc).
please read orm tutorial on querying
Comments
Post a Comment