pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Hauser <chauser@acpub.duke.edu>
To: pgsql-sql@postgresql.org
Subject: CURSOR/FETCH vs LIMIT/OFFSET
Date: Wed, 8 May 2002 11:16:51 -0400
Message-ID: <a05010402b8fef1752c72@[152.3.11.193]> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <a05010402b8fef1752c72@[152.3.11.193]>
Permalink:  ../a05010402b8fef1752c72@%5B152.3.11.193%5D/
Also on:    postgresql.org/message-id/a05010402b8fef1752c72@[152.3.11.193]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chauser@acpub.duke.edu
  Subject: Re: CURSOR/FETCH vs LIMIT/OFFSET
  In-Reply-To: <a05010402b8fef1752c72@[152.3.11.193]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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