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)),
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
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
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
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
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 =
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
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
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