Skip site navigation (1) Skip section navigation (2)

Re: Using a cursor vs. not ?

From: "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com>
To: "Paula Greve" <greve(at)securecomputing(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Using a cursor vs. not ?
Date: 2000-08-29 00:18:28
Message-ID: 00082820305701.00197@comptechnews (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Mon, 28 Aug 2000, Paula Greve wrote:
> Hi!
> Sorry for the very trivial and probably obvious question -- but I have
> looked all over the documentation and have been unable to find a discussion
> on this.
> When do I want to declare and use a cursor -- and why?

You want to use a cursor when you have a query that (potentially) returns a
large number of rows, so many, that it might exhaust memory if returned all at

The cursor allows you to submit the query and then retrieve one or more of the
result rows/tuples at a time, which keeps memory usage low.  You can move
forward and backward in the results to retrieve the same rows many times if you
need to without having to query again.

A cursor is also useful if you want to return information in pages at a time
for some application.  You can move forward by x-per-page * pagenumber, to
retrieve the page wanted from the results.  You have to include a SORT BY
in the query that is used to create the cursor to get pages in a meaningful

Hope this helps a little.  I might be able to come up with some examples if you
can't find any.

-------- Robert B. Easter  reaster(at)comptechnews(dot)com ---------
- CompTechNews Message Board -
- CompTechServ Tech Services -
---------- ------------

In response to

pgsql-novice by date

Next:From: S.A.PamungkasDate: 2000-08-29 03:44:19
Subject: destroying db / closing access
Previous:From: Brian D. WoodruffDate: 2000-08-28 18:32:52
Subject: Re: backend closed

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group