Re: Can This be done - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Can This be done
Date
Msg-id 20020514112906.A8900@svana.org
Whole thread Raw
In response to Re: Can This be done  (Uros Gruber <uros@sir-mag.com>)
List pgsql-general
On Mon, May 13, 2002 at 08:23:29PM +0200, Uros Gruber wrote:
> Hi,
>
> I know that select return a number of records, but i i use
> LIMIT i can't know how many row actualy is, because it's
> alway smaller than limit.
>
> Only solution I know for now is with 2 queryes. First query
> to get all the data, and than second with limit. But this is
> not something i want.

I'm afraid you're stuck here. To work out how many rows there are, the
system has to evaluate the entire query. And if you're evaluating the entire
query, you may as well use the entire result set.

It may be helpful to decide whether you really need the number of rows. For
example, Google only provides an estimate unless it really is a small number
of matches. If all you want it know whether to provide a next link, do limit
(number of rows+1). If the extra now is there, provide a next link.

HTH,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Canada, Mexico, and Australia form the Axis of Nations That
> Are Actually Quite Nice But Secretly Have Nasty Thoughts About America

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Quotes in SQL
Next
From: Tom Lane
Date:
Subject: Re: Configure problems with readline Mandrake 8.2 and postgres 7.2.1