Outside of the for loop, query() returns a Query object while all() execute the query and store the result in a list, according to the document. My question is when in a loop, the query object is obviously executed, is there still any benefit to use query() over query().all()?
Asked
Active
Viewed 49 times
1
David Zheng
- 797
- 7
- 21
-
This question has been asked here: http://stackoverflow.com/questions/1078383/sqlalchemy-difference-between-query-and-query-all-in-for-loops – CodeLikeBeaker Jun 26 '15 at 19:20
-
Hi, @Green Chili. I did read that post. It seems `query()` is more memory friendly than `query().all()`. Does that mean when looping through rows, it's always better to use `query()`? I really didn't see any benefit of using `all()` in the context of looping. – David Zheng Jun 26 '15 at 19:32
-
there won't be any performance differences really. Not unless you were to break after n number of rows versus looping through millions of records. – CodeLikeBeaker Jun 26 '15 at 21:13