pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCURSOR/FETCH vs LIMIT/OFFSET
2+ messages / 2 participants
[nested] [flat]
* CURSOR/FETCH vs LIMIT/OFFSET
@ 2002-05-08 15:16 Charles Hauser <chauser@acpub.duke.edu>
0 siblings, 1 reply; 2+ messages in thread
From: Charles Hauser @ 2002-05-08 15:16 UTC (permalink / raw)
To: pgsql-sql
Hi,
re: displaying results of query.
Trying to work out details of how to let users page back and forth
among a multi-page list of results.
Problem: I need to know the total number of tuples the query would
return in order to decide if there are more to display.
1) Use CURSOR and FETCH
$res= $con->exec(
"BEGIN WORK;
DECLARE gene_result CURSOR FOR
SELECT blah blah
ORDER BY blah;
FETCH $offset IN gene_result
");
$result->ntuple: returns only the number set by $offset, not TOTAL for query.
2) use LIMIT OFFSET
same problem,
$result->ntuple: returns only the number set by LIMIT, OFFSET, not
TOTAL for query.
So there has to be a way to glean both the TOTAL and the SUBSET returned?
Searching the postgresql archives obviously can deal with this
http://archives.postgresql.org/pgsql-sql/
'Displaying documents 11-20 of total 243 found.'
--
Regards,
Chuck
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: CURSOR/FETCH vs LIMIT/OFFSET
@ 2002-05-08 20:31 Philip Hallstrom <philip@adhesivemedia.com>
parent: Charles Hauser <chauser@acpub.duke.edu>
0 siblings, 0 replies; 2+ messages in thread
From: Philip Hallstrom @ 2002-05-08 20:31 UTC (permalink / raw)
To: Charles Hauser <chauser@acpub.duke.edu>; +Cc: pgsql-sql
Why not at the very beginning do something like "SELECT COUNT(*)..." and
store that as $totalTuples... then use limit/offset...
-philip
On Wed, 8 May 2002, Charles Hauser wrote:
> Hi,
>
> re: displaying results of query.
>
> Trying to work out details of how to let users page back and forth
> among a multi-page list of results.
>
> Problem: I need to know the total number of tuples the query would
> return in order to decide if there are more to display.
>
> 1) Use CURSOR and FETCH
>
> $res= $con->exec(
> "BEGIN WORK;
> DECLARE gene_result CURSOR FOR
> SELECT blah blah
> ORDER BY blah;
> FETCH $offset IN gene_result
> ");
>
> $result->ntuple: returns only the number set by $offset, not TOTAL for query.
>
> 2) use LIMIT OFFSET
>
> same problem,
> $result->ntuple: returns only the number set by LIMIT, OFFSET, not
> TOTAL for query.
>
> So there has to be a way to glean both the TOTAL and the SUBSET returned?
>
> Searching the postgresql archives obviously can deal with this
> http://archives.postgresql.org/pgsql-sql/
> 'Displaying documents 11-20 of total 243 found.'
>
> --
> Regards,
>
> Chuck
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-05-08 20:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-08 15:16 CURSOR/FETCH vs LIMIT/OFFSET Charles Hauser <chauser@acpub.duke.edu>
2002-05-08 20:31 ` Philip Hallstrom <philip@adhesivemedia.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox