On Nov 4, 2011, at 4:54 AM, Stefano Fontanelli wrote:

> Il 04/11/11 03.08, Mark Erbaugh ha scritto:
>> 
>> On Nov 3, 2011, at 2:54 PM, Stefano Fontanelli wrote:
>> 
>>> Il 03/11/11 19.18, Mark Erbaugh ha scritto:
>>>> Using the query object count() method generates a sub-query (as per the 
>>>> docs). The docs say to use func.count to avoid the subquery. func.count 
>>>> seems to require a field object. Is there a way to generate a query that 
>>>> essentially becomes 'select count(*) from table' using the ORM, not the 
>>>> SQL generator?
>>>> 
>>>> Thanks,
>>>> Mark
>>>> 
>>> Did you try func.count('*')?
>> How would you specify the table you want counted?  I trued 
>> func.count('table.*') and that didn't work.
> 
> Check the manual: http://www.sqlalchemy.org/docs/orm/tutorial.html#counting
> 
> To achieve our simple SELECT count(*) FROM table, we can apply it as:
> 
> SQL>>> session.query(func.count('*')).select_from(User).scal
> ar()
> 
> Is that right for you?

Stefano,

Thanks. I missed that in the documentation and it does indeed generate the 
expected SQL (at least with SQLite).

Mark

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to