Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVJ7u-0001uv-PX for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Aug 2016 13:55:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVJ7u-0000Pp-CP for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Aug 2016 13:55:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVIJR-0004iD-OU for pgsql-bugs@postgresql.org; Thu, 04 Aug 2016 13:03:49 +0000 Received: from forward15j.cmail.yandex.net ([5.255.227.179]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVIJN-0002Wq-FK for pgsql-bugs@postgresql.org; Thu, 04 Aug 2016 13:03:47 +0000 Received: from mxback8h.mail.yandex.net (mxback8h.mail.yandex.net [84.201.186.17]) by forward15j.cmail.yandex.net (Yandex) with ESMTP id 80827214CB; Thu, 4 Aug 2016 16:03:42 +0300 (MSK) Received: from web8h.yandex.ru (web8h.yandex.ru [84.201.186.37]) by mxback8h.mail.yandex.net (nwsmtp/Yandex) with ESMTP id OkK3DZ2ZIr-3gB02VU1; Thu, 04 Aug 2016 16:03:42 +0300 Received: by web8h.yandex.ru with HTTP; Thu, 04 Aug 2016 16:03:42 +0300 From: "klimych@tut.by" To: Andrew Gierth Cc: "pgsql-bugs@postgresql.org" In-Reply-To: <874m72ggi4.fsf@news-spur.riddles.org.uk> References: <20160803095301.1420.50016@wrigleys.postgresql.org> <874m72ggi4.fsf@news-spur.riddles.org.uk> Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope MIME-Version: 1.0 Message-Id: <634371470315822@web8h.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Thu, 04 Aug 2016 16:03:42 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 X-Pg-Spam-Score: -2.6 (--) 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 Thank you! Sorry, I should read the documentation more carefully (athough I didnt't expect to find explanation of such behaviour in "Returning Cursors" section, as well as I didn't belive such behaviour could be made on purpose). And thanks again for workaround! It seems to be the only way to use cursors in pl/pgsql (the weirdest thing I've ever seen, I should say) 03.08.2016, 16:03, "Andrew Gierth" : >>>>>>  "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