On Feb 23, 2008, at 4:02 AM, James wrote:

>
> Hi,
> So it appears that Query.count() returns a row count for that
> particular query, which len(Query.all()) obviously returns an object
> count.
>
> In the case of a join where several rows are automagically folded into
> a single object, this count can differ.
>
> Is there a shortcut for the case where I want to know the object
> count, but don't want to retrieve all the objects from the database to
> do so?
>
> Failing that, what's the best practice for a workaround - I've been
> fiddling with distinct() and group_by() but I'm sure someone must have
> hit this too!
>

using query.distinct() along with whatever joins and then count()  
should be counting only distinct rows of the primary table in the  
query, since only those columns get placed into the columns clause of  
the select. as long as you aren't calling add_entity() or add_column().

of course we love examples here if you'd like to show us what you're  
doing.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to