Re: count and limit

From: "Fabio Victora Hecht" <fabiovh(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: count and limit
Date: 2006-08-20 00:56:41
Message-ID: d2bb3d100608191756g31f3fbebobd5cf81126f59dd8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ok, so I think the best that can be done is to EXPLAIN the query and check
if it's gonna take long. If it is, I could use the estimated count.

Thanks,

Fabio

On 8/17/06, Chris <dmagick(at)gmail(dot)com> wrote:
>
> Michael Fuhr wrote:
> > 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
> >
>
> Thanks for the pointer :)
>
> I do a lot of those type of things too so this may be a way to handle it
> better.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2006-08-20 01:46:56 Re: Cast null string '' to integer 0
Previous Message Michael Fuhr 2006-08-19 22:50:08 Re: text formatting in a query, a la sprintf