Re: Way to use count() and LIMIT?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Joe Koenig <joe(at)jwebmedia(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Way to use count() and LIMIT?
Date: 2001-12-19 14:16:07
Message-ID: 20011220011606.B16349@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Dec 19, 2001 at 08:13:50AM -0600, Joe Koenig wrote:
> This is exactly right. The table I'm searching has 220,000 records right
> now, and growing. The "Rock" category within "CD's" will return over
> 53,000 results. The count isn't so much for display, as for knowing
> whether or not to put a "next" button on the page. I don't want to
> always have next buttons, but not always have more results. There is
> currently the option to browse through results based on the first letter
> of the result, which I guess I could make as the 3rd step and not run
> the query that currently returns 53,000 results until they narrow it
> down more. I wasn't really expecting this to be possible, but PG does so
> many other things that I didn't think was possible, so I thought I'd ask :)

But that's easy. Simply ask the database for one more record that you're
going to display. If you get that extra record, then display the next
button, otherwise don't. The count is irrelevent.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org>
http://svana.org/kleptog/
> Terrorists can only take my life. Only my government can take my freedom.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-12-19 14:25:17 Re: Query hangs when getting too complex...
Previous Message Joe Koenig 2001-12-19 14:13:50 Re: Way to use count() and LIMIT?