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 2F8E39DC82F for ; Wed, 28 Dec 2005 13:04:05 -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 03198-06 for ; Wed, 28 Dec 2005 13:04:03 -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 C3F7C9DC818 for ; Wed, 28 Dec 2005 13:04:02 -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 jBSH3vBq006820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Dec 2005 10:04:00 -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 jBSH3v9Z029386; Wed, 28 Dec 2005 10:03:57 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jBSH3v3n029385; Wed, 28 Dec 2005 10:03:57 -0700 (MST) (envelope-from mfuhr) Date: Wed, 28 Dec 2005 10:03:57 -0700 From: Michael Fuhr To: Tom Lane Cc: Don Croata , pgsql-sql@postgresql.org Subject: Re: Cursors and recursion Message-ID: <20051228170357.GA29290@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: <17343.1135784905@sss.pgh.pa.us> 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/222 X-Sequence-Number: 23764 On Wed, Dec 28, 2005 at 10:48:25AM -0500, Tom Lane wrote: > Don Croata writes: > > It's a function who has a cursor and calls itself, but the problem raises > > after the first recursion, when PgSQL complains: > > > ERROR: cursor "cur" already in use > > > Are the cursors kept globally? or cached like TEMP TABLE? > > Cursor names are global within a particular session. > > IIRC there is a syntax for opening a cursor without specifying a name, > in which case plpgsql will pick one that's not in use. This is probably > what you want to use. Or, if possible, use "FOR record_or_row IN query LOOP" instead of an explicit cursor. http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING -- Michael Fuhr