From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Don Croata <el(dot)croata(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Cursors and recursion |
Date: | 2005-12-29 02:48:16 |
Message-ID: | 20051229024816.GA32249@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-12-29 03:03:19 | Re: DISTINCT with NULLs and INT fields |
Previous Message | George Pavlov | 2005-12-29 02:00:59 | Re: DISTINCT with NULLs and INT fields |