Re: getting count for a specific querry

From: Rod Taylor <pg(at)rbt(dot)ca>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-sql(at)postgresql(dot)org, Joel Fradkin <jfradkin(at)wazagua(dot)com>, Ragnar Hafstað <gnari(at)simnet(dot)is>
Subject: Re: getting count for a specific querry
Date: 2005-04-08 16:51:32
Message-ID: 1112979092.92363.250.camel@home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> > select * from mytable where somecondition AND uniquecol>?
> > ORDER by uniquecol limit 50 OFFSET 50;
>
> > where the ? is placeholder for last value returned by last query.
>
> Uh, you don't want the OFFSET there do you? But otherwise, yeah,
> this is a popular solution for paging through some rows. Doesn't really
> help with the problem of counting the total dataset though ...

In the past I've done an EXPLAIN and parsed the plan to see what
PostgreSQL estimated for the number of <somecondition>. If less than
$threshhold, I would do a count(*). If more than $threshhold I would
display to the user "approx N records".

This seemed to be good enough for most cases.
--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stef 2005-04-08 16:51:47 Numeric and CSV under 8.0.1 ?
Previous Message Tom Lane 2005-04-08 16:32:03 Re: getting count for a specific querry