AttributeError: ResultProxy instance has no attribute '__len__'

485 views
Skip to first unread message

George Sakkis

unread,
Oct 19, 2006, 9:53:55 PM10/19/06
to sqlalchemy
I tried to get the length of a result set and I ran into the this
error. While I understand that ResultProxy is modeled more like an
iterator than a sequence, I introspected the proxy object and it turns
out it has a 'rowcount' attribute which stores the expected length. Is
there a reason why there's not a __len__ that returnes this rowcount ?

Thanks,
George

Michael Bayer

unread,
Oct 19, 2006, 10:31:54 PM10/19/06
to sqlalchemy
rowcount stores the number of rows that were located during an INSERT,
UPDATE, or DELETE statement, and is undefined during SELECT. the
"length" of a result set is generally not known until it is completely
fetched, as the database typcially starts returning rows over the wire
before it has even finished locating all rows (unless the results were
ordered or otherwise grouped in some way).

to get the length of a particular result usually entails either fully
fetching the result, or calling a separate select of "count()" with the
same criterion.

Reply all
Reply to author
Forward
0 new messages