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 simpleSELECTcount(*)FROMtable, we can apply it as:

SQL  <http://www.sqlalchemy.org/docs/orm/tutorial.html#>>>>  
session.query(func.count('*')).select_from(User).scalar()


Is that right for you?


--
Ing. Stefano Fontanelli
Asidev S.r.l.
Via Osteria Bianca, 108/A 50053 Empoli (Firenze)
Tel. (+39) 333 36 53 294   Fax. (+39) 0571 1 979 978
E-mail: [email protected]   Web: www.asidev.com
Skype: stefanofontanelli

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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