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

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to