Re: How to get the total number of rows returned by query when using a cursor?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Egor Shipovalov" <pgsql_list(at)eonline(dot)ru>
Cc: "Pgsql-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to get the total number of rows returned by query when using a cursor?
Date: 2003-09-23 15:26:32
Message-ID: 17232.1064330792@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Egor Shipovalov" <pgsql_list(at)eonline(dot)ru> writes:
> I'm implementing paging through search results using cursors. Is there a
> better way to know total number of rows under a cursor than running a
> separate COUNT(*) query? I think PostgreSQL is bound to know this number
> after the first FETCH, isn't it?

Why would you think that? In general Postgres doesn't know the number
of rows until it reaches the end of the query.

> On a side note, why queries using LIMIT are SO terribly slow, compared to
> cursors and sometimes even ones without LIMIT?

Generally they're not particularly slow. Perhaps you should show us the
EXPLAIN ANALYZE results for your problem case.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2003-09-23 15:32:38 Re: State of Beta 2
Previous Message scott.marlowe 2003-09-23 15:26:03 Re: About GPL and proprietary software