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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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
once.

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
order.

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 http://www.comptechnews.com/ -
- CompTechServ Tech Services http://www.comptechserv.com/ -
---------- http://www.comptechnews.com/~reaster/ ------------

In response to

Browse pgsql-novice by date

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