count(*) and limit

From: Orion <o2(at)trustcommerce(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: count(*) and limit
Date: 2001-10-11 20:31:59
Message-ID: 9q4vc1$2nej$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


I have a interface where users are paging through results of a query. In
order to do so I need to

select count(*) from data where stuff;

To find out how many pages of data there are ( needed for the navigation
bar)

and then I need to

select * from data where stuff limit X offset y;

Now, postgres has to get the whole result before running the limit.

Is there some trick to get how many rows there would be without the limit
so I dont need to run the extra count(*) query? It seems like a waste.

Orion

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2001-10-11 20:38:37 Re: Server crash caused by CHECK on child
Previous Message Allan Engelhardt 2001-10-11 20:22:43 Re: indexing and LIKE