[orm-devel] count vs len()

Charles Brandt lists at st.imul.us
Wed Mar 31 04:19:15 CEST 2004


(sorry for all of the email... I thought it might be nice to separate these
topics out by thread).

> >One feature that I'm thinking about adding is a count method to the
> >datasource.select.  (inspired by SQLObject...)  This would wrap the SQL
> >COUNT(*) statement and might be handy when doing selects in batches.  I
was
> >using this as a low cost test for the existence of a specific column
value,
> >but fetchall() should work fine in this case since there should only ever
be
> >zero or one value.
> Hm.. I'll think about a count() function.
> SelectResults do have a len(), see next question.

I was thinking that on large tables fetchall could be inefficient if the
length is the only data point required.  I recently noticed the
DelayedResult and was thinking maybe this could yield similar results
without a potentially expensive select statement.  I'll investigate further.
For now I'm just using the execute for the custom statement (brittle, yes
:) ):

        cursor = conn.execute("SELECT COUNT(*) FROM map_items")
        return cursor.rowcount

-Charles




More information about the orm-devel mailing list