From: | Ragnar Hafstað <gnari(at)simnet(dot)is> |
---|---|
To: | Andrew Sullivan <ajs(at)crankycanuck(dot)ca> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: getting count for a specific querry |
Date: | 2005-04-08 16:17:45 |
Message-ID: | 1112977065.7444.30.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Fri, 2005-04-08 at 11:07 -0400, Andrew Sullivan wrote:
> On Fri, Apr 08, 2005 at 09:29:13AM -0400, Joel Fradkin wrote:
> >
> > Is there a fast way to get the count?
>
> Not really, no. You have to perform a count() to get it, which is
> possibly expensive. One way to do it, though, is to do
>
> SELECT count(*) FROM tablename WHERE condition LIMIT n;
>
> or something like that. Assuming the condition is reasonably limited
> (i.e. it's not going to cost you a fortune to run this), you'll get
> the right number back if the number is < n or else you'll get
> n.
come again ?
test=# select count(*) from a;
count
-------
3
(1 row)
test=# select count(*) from a limit 2;
count
-------
3
(1 row)
the LIMIT clause limits the number of rows returned by the select,
in this case 1 row.
maybe you mean something like:
test=# select count(*) from (select * from a limit 2) as foo;
count
-------
2
(1 row)
gnari
From | Date | Subject | |
---|---|---|---|
Next Message | Ragnar Hafstað | 2005-04-08 16:25:46 | Re: getting count for a specific querry |
Previous Message | Richard Huxton | 2005-04-08 16:02:25 | Re: Question on triggers and plpgsql |