Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUvqG-0006Bl-An for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Aug 2016 13:04:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bUvqF-0000eR-UC for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Aug 2016 13:04:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bUvpc-0008OI-OK for pgsql-bugs@postgresql.org; Wed, 03 Aug 2016 13:03:32 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bUvpU-00036a-TR for pgsql-bugs@postgresql.org; Wed, 03 Aug 2016 13:03:32 +0000 Received: from localhost ([127.0.0.1]:45911 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.84 (FreeBSD)) (envelope-from ) id 1bUvpS-000J3H-Nj; Wed, 03 Aug 2016 13:03:22 +0000 From: Andrew Gierth To: klimych@tut.by Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope In-Reply-To: <20160803095301.1420.50016@wrigleys.postgresql.org> (klimych@tut.by's message of "Wed, 03 Aug 2016 09:53:01 +0000") Message-ID: <874m72ggi4.fsf@news-spur.riddles.org.uk> References: <20160803095301.1420.50016@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix) Date: Wed, 03 Aug 2016 14:03:22 +0100 MIME-Version: 1.0 Content-Type: text/plain X-Pg-Spam-Score: -3.1 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org >>>>> "klimych" == klimych writes: klimych> Executing of the code gives error "cursor "cur" already in klimych> use". The cursor name (portal name) is global to the session, and for a bound cursor it defaults to the name of the cursor variable: 40.7.3.5. Returning Cursors [...] 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. It's a bit ugly, but you can do declare cur for select 1; begin cur := null; -- force a unique generated portal name open cur; //... -- Andrew (irc:RhodiumToad) -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs