pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Don Croata <el.croata@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Cursors and recursion
Date: Wed, 28 Dec 2005 19:48:16 -0700
Message-ID: <20051229024816.GA32249@winnie.fuhr.org> (raw)
In-Reply-To: <be9533860512281137u42cc2a16hcd2d5b703a809bdd@mail.gmail.com>
References: <be9533860512280629m1c1163bm73fef37f17541423@mail.gmail.com>
	<17343.1135784905@sss.pgh.pa.us>
	<be9533860512281137u42cc2a16hcd2d5b703a809bdd@mail.gmail.com>

On Wed, Dec 28, 2005 at 04:37:21PM -0300, Don Croata wrote:
> Please, if someone recalls a link, book, piece of code or anything with info
> about this technique for PL/PgSQL (8.1), please let us know. We've been
> searching into google, groups.google, http://archives.postgresql.org and
> http://www.postgresql.org/docs/8.1/interactive with no results. Most of the
> answers are related to unclosed cursors for the "ERROR: cursor ... already
> in use" message.

See the "Cursors" section of the PL/pgSQL documentation and read
about unbound cursors:

http://www.postgresql.org/docs/8.1/interactive/plpgsql-cursors.html

"Note:  A bound cursor variable is initialized to the string value
representing its name, so that the portal name is the same as the
cursor variable name, unless the programmer overrides it by assignment
before opening the cursor.  But an unbound cursor variable defaults
to the null value initially, so it will receive an automatically-generated
unique name, unless overridden."

For example, instead of

  DECLARE
      cur CURSOR FOR SELECT ...;
  BEGIN
      OPEN cur;

use

  DECLARE
      cur refcursor;
  BEGIN
      OPEN cur FOR SELECT ...;

But as I mentioned in a previous post, it's usually easier to use
FOR-IN-LOOP.

-- 
Michael Fuhr



view thread (5+ messages)

Message-ID: <20051229024816.GA32249@winnie.fuhr.org>
Permalink:  ../20051229024816.GA32249@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20051229024816.GA32249@winnie.fuhr.org

 · 

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: mike@fuhr.org, el.croata@gmail.com
  Subject: Re: Cursors and recursion
  In-Reply-To: <20051229024816.GA32249@winnie.fuhr.org>

* 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