Re: Can This be done

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Uros Gruber <uros(at)sir-mag(dot)com>
Cc: Steve Lane <slane(at)fmpro(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Can This be done
Date: 2002-05-14 01:29:06
Message-ID: 20020514112906.A8900@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2002-05-14 01:31:03 Re: Quotes in SQL
Previous Message Bill Moran 2002-05-14 01:26:20 Re: Use of OIDS as primary keys