Re: how many rows? [was Re: fetching rows] - Mailing list pgsql-sql

From Robert B. Easter
Subject Re: how many rows? [was Re: fetching rows]
Date
Msg-id 0011171903570A.30061@comptechnews
Whole thread Raw
In response to how many rows? [was Re: fetching rows]  (Arnaud Vandyck <arnaud@ressource-toi.org>)
List pgsql-sql
On Friday 17 November 2000 04:01, Arnaud Vandyck wrote:
> "Robert B. Easter" wrote:
> > > you can't do that with a cursor, but you can use they mysql-ism called
> > > a limit clause.  for example, to fetch rows 26-50 from that query,
> > > you'd do:
> > >
> > > select * from films limit 25,26;
> > >
> > > or
> > >
> > > select * from files limit 25 offset 26;
>
> I did know it was possible but did not know how to do, thanks (It was
> not my question but I'm glad to see the solution:)
>
> and how can I know how many rows are returned by the query?
>

I don't know exactly.  I don't know of any way to find the total number of 
rows in a cursor.  If you really need to know, you'll have to run a count(*) 
first, then make the cursor using the same select almost.  Once you get the 
count(*), you can then use MOVE and FETCH to get the page you want.

If someone has done it a better way, I'd like to hear how.  However, 
sometimes it is possible to cache a count(*) value somewhere in the database 
so it doesn't have to be found everytime - it depends on your database and 
what the select is if you can store the count in advance somehow.

> --
> Arnaud
> ( http://www.ressource-toi.org )

-- 
-------- Robert B. Easter  reaster@comptechnews.com ---------
- CompTechNews Message Board   http://www.comptechnews.com/ -
- CompTechServ Tech Services   http://www.comptechserv.com/ -
---------- http://www.comptechnews.com/~reaster/ ------------


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why is this doing a seq scan?
Next
From: Roberto Mello
Date:
Subject: Re: how many rows? [was Re: fetching rows]]