Are there any significant differences (performance, or otherwise) between the following two ways of getting a list of results?
users: Sequence[User] = session.execute(select(User)).scalars().all()
users: Sequence[User] = list(session.execute(select(User)).scalars())
The second seems more pythonic to me, and is possible because ScalarResult
is iterable over its rows, so calling list(...scalars())
just iterates over the ScalarResult
object. However, since .all()
also exists, I assume there must be some reason for it, so maybe it’s more efficient to use .all()
?
What are the differences between the two, and what, if anything, goes on behind the scenes that causes the difference?