You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Jack O'Connor <jo...@bristol.ac.uk> on 2007/07/23 12:49:56 UTC
counting rows
A question about efficiency: Counting the number of rows in a table.
Currently, I run a select query, then iterate through the rows,
incrementing a counter. This takes too long. Is there a way to use the
SQL command:
SELECT count(*) FROM <table>
Or something similar, that quickly returns the number of rows from a
select query?
Thanks
Jack
Re: counting rows
Posted by Andrus Adamchik <an...@objectstyle.org>.
And another 3.0 plug :-)
Admittedly getting results of scalar queries as Maps can be
confusing, as (a) you have to unwrap them and (b) it is not always
clear what the map keys are. So we are experimenting with a different
presentation of the results. There's more work to be done on that,
but you can do this already:
String ejbql = "select count(p) from Painting p";
EJBQLQuery query = new EJBQLQuery(ejbql);
Number count = (Number) DataObjectUtils.objectForQuery(context,
query);
Andrus
On Jul 23, 2007, at 4:57 PM, Aristedes Maniatis wrote:
>
> On 23/07/2007, at 8:49 PM, Jack O'Connor wrote:
>
>> Or something similar, that quickly returns the number of rows from
>> a select query?
>
> If you don't need the actual records, but just the count, then you
> can use one of the several mechanisms to do this. Here's one:
>
> http://cayenne.apache.org/doc/customizing-queries.html
>
>
> Ari Maniatis
>
>
> -------------------------->
> Aristedes Maniatis
> phone +61 2 9660 9700
> PGP fingerprint 08 57 20 4B 80 69 59 E2 A9 BF 2D 48 C2 20 0C C8
>
>
Re: counting rows
Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 23/07/2007, at 8:49 PM, Jack O'Connor wrote:
> Or something similar, that quickly returns the number of rows from
> a select query?
If you don't need the actual records, but just the count, then you
can use one of the several mechanisms to do this. Here's one:
http://cayenne.apache.org/doc/customizing-queries.html
Ari Maniatis
-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2 A9 BF 2D 48 C2 20 0C C8
AW: counting rows
Posted by Peter Schröder <Pe...@freenet-ag.de>.
hi jack,
search the list on count query.
-----Ursprüngliche Nachricht-----
Von: Jack O'Connor [mailto:jo4185@bristol.ac.uk]
Gesendet: Montag, 23. Juli 2007 12:50
An: user@cayenne.apache.org
Betreff: counting rows
A question about efficiency: Counting the number of rows in a table.
Currently, I run a select query, then iterate through the rows,
incrementing a counter. This takes too long. Is there a way to use the
SQL command:
SELECT count(*) FROM <table>
Or something similar, that quickly returns the number of rows from a
select query?
Thanks
Jack