Re: count and limit

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Chris <dmagick(at)gmail(dot)com>
Cc: Fabio Victora Hecht <fabiovh(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: count and limit
Date: 2006-08-18 00:49:33
Message-ID: 20060818004932.GA93594@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 18, 2006 at 10:34:44AM +1000, Chris wrote:
> Fabio Victora Hecht wrote:
> >I was wondering if there's a way to count the results of a query and
> >return part of the result set it in one query (LIMIT). Because I usually
> >have to count the results using one query (to tell the user how many
> >records match the criteria) and show the first 20 records.
>
> I was going to suggest a cursor but I don't think you can get the number
> of results a cursor has :(

You can but you have to MOVE to the end, so the backend has to visit
each tuple just as it would for COUNT. I answered a similar question
recently:

http://archives.postgresql.org/pgsql-novice/2006-07/msg00220.php

--
Michael Fuhr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris 2006-08-18 00:52:32 Re: count and limit
Previous Message Tom Lane 2006-08-18 00:47:10 Re: count and limit