[sqlalchemy] Re: count() not working?

2009-04-27 Thread Michael Bayer
dont use query.count() for anything but the most simple counts of entities. if you're already creating a complex query using aggregate functions and such, query the func.count() values directly using query(func.count(whatever)), query.value(func.count(whatever)),

[sqlalchemy] Re: .count() returns wrong count

2008-04-10 Thread Michael Bayer
On Apr 10, 2008, at 3:31 AM, Dieter Verfaillie wrote: Hello, I've created a single table inheritance hierarchy where SpecialThing inherits from BasicThing. When I session.query(BasicThing).count() the correct count is returned, but session.query(SpecialThing).count() returns the count

[sqlalchemy] Re: count function problem

2007-03-15 Thread jose
Glauco wrote: Michael Bayer ha scritto: On Mar 14, 2007, at 12:49 PM, Glauco wrote: This is perfect but when i try to use count function the SQL composer try to do an expensive sql. In [63]: print select([tbl['azienda'].c.id], tbl['azienda']).count() *SELECT count(id) AS

[sqlalchemy] Re: count function problem

2007-03-15 Thread Michael Bayer
On Mar 15, 2007, at 5:09 AM, Glauco wrote: because i expect that engine do a SELECT COUNT FROM BLABLA and no a SELECT COUNT FROM ( SELECT BLABLA) i think this is expensive for my DataBase. its not. optimizers can usually figure things like that out. I've done a lot of try this

[sqlalchemy] Re: count function problem

2007-03-14 Thread Michael Bayer
On Mar 14, 2007, at 12:49 PM, Glauco wrote: This is perfect but when i try to use count function the SQL composer try to do an expensive sql. In [63]: print select([tbl['azienda'].c.id], tbl['azienda']).count() SELECT count(id) AS tbl_row_count FROM (SELECT azienda.id AS id FROM

[sqlalchemy] Re: count(*) function

2007-01-20 Thread milena
It worked. Thanks! On Jan 15, 11:37 am, Marco Mariani [EMAIL PROTECTED] wrote: milenawrote: I have tried select([func.count(*)], from_obj=[table_name]).execute() but it didn't workI suppore you're not using mappers, so this is the fastest method: number_of_rows =

[sqlalchemy] Re: count(*) function

2007-01-15 Thread Marco Mariani
milena wrote: I have tried select([func.count(*)], from_obj=[table_name]).execute() but it didn't work I suppore you're not using mappers, so this is the fastest method: number_of_rows = table.count().execute().fetchone()[0] where table is the table object

[sqlalchemy] Re: count(*) function

2007-01-15 Thread Sébastien LELONG
I have tried select([func.count(*)], from_obj=[table_name]).execute() but it didn't work I think you should try to specify a column in your count or leave it empty (didn't try). If you're using mapped objects, you can use the SelectResults extension: from sqlalchemy.ext.selectresults

[sqlalchemy] Re: count()

2006-12-08 Thread Michael Bayer
if you are going to fetch all results in all cases, then len(result) is fine. if the result list is enormous and youre only going to fetch a small portion of it within a request, the count() query as a separate operation is better. --~--~-~--~~~---~--~~ You