X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 251579DC80A for ; Wed, 28 Dec 2005 22:48:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98226-06 for ; Wed, 28 Dec 2005 22:48:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id EFEC99DC83E for ; Wed, 28 Dec 2005 22:48:17 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jBT2mGXT007245 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Dec 2005 19:48:19 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jBT2mGEL032317; Wed, 28 Dec 2005 19:48:16 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jBT2mGha032316; Wed, 28 Dec 2005 19:48:16 -0700 (MST) (envelope-from mfuhr) Date: Wed, 28 Dec 2005 19:48:16 -0700 From: Michael Fuhr To: Don Croata Cc: pgsql-sql@postgresql.org Subject: Re: Cursors and recursion Message-ID: <20051229024816.GA32249@winnie.fuhr.org> References: <17343.1135784905@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.05 required=5 tests=[AWL=0.050] X-Spam-Score: 0.05 X-Spam-Level: X-Archive-Number: 200512/236 X-Sequence-Number: 23778 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