Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVJ8B-0001vR-72 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Aug 2016 13:56:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVJ8A-00010C-Q4 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Aug 2016 13:56:14 +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 1bVIBn-0001sb-Bu for pgsql-bugs@postgresql.org; Thu, 04 Aug 2016 12:55:55 +0000 Received: from forward11j.cmail.yandex.net ([5.255.227.175]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVIBZ-0002R5-UN for pgsql-bugs@postgresql.org; Thu, 04 Aug 2016 12:55:53 +0000 Received: from mxback7m.mail.yandex.net (mxback7m.mail.yandex.net [37.140.138.67]) by forward11j.cmail.yandex.net (Yandex) with ESMTP id 3F31420D04; Thu, 4 Aug 2016 15:55:37 +0300 (MSK) Received: from web11m.yandex.ru (web11m.yandex.ru [37.140.138.102]) by mxback7m.mail.yandex.net (nwsmtp/Yandex) with ESMTP id TJ3uKVPr34-ta0uoke1; Thu, 04 Aug 2016 15:55:36 +0300 Received: by web11m.yandex.ru with HTTP; Thu, 04 Aug 2016 15:55:36 +0300 From: klimych@tut.by To: Pavel Stehule Cc: "pgsql-bugs@postgresql.org" In-Reply-To: References: <20160803095301.1420.50016@wrigleys.postgresql.org> Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope MIME-Version: 1.0 Message-Id: <819481470315336@web11m.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Thu, 04 Aug 2016 15:55:36 +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 Wow. Thank you! Sorry, i should read the documentation more carefully 03.08.2016, 16:04, "Pavel Stehule" : > 2016-08-03 11:53 GMT+02:00 : >> The following bug has been logged on the website: >> >> Bug reference:      14275 >> Logged by:          Oleg Klimovich >> Email address:      klimych@tut.by >> PostgreSQL version: 9.5.3 >> Operating system:   Windows 7, Windows 8, Ubuntu 14.04 >> Description: >> >> DO $$ >> DECLARE >>  cur cursor for select 1; -- (1) >> BEGIN >>   open cur; -- (2) >> >>   DECLARE >>     cur cursor for select 2; -- (3) >>   BEGIN >>     open cur; -- (4) >>     close cur; -- (5) >>   END; >> >>   close cur; -- (6) >> end $$; >> >> Executing of the code gives error "cursor "cur" already in use". Evedently, >> PG in statement (4) refers to the variable, defined in statement (1). (and I >> expect it should be variable, defined in statement (3)). >> Futhermore, same error exists even across different functions: >> >> create function func1() returns void as $$ >> declare >>   cur cursor for select 1; >> BEGIN >>   open cur; >>   close cur; >> end >> $$ >>  LANGUAGE 'plpgsql'; >> >> create function func2() returns void as $$ >> declare >>   cur cursor for select 1; >> BEGIN >>   open cur; >> >>   PERFORM func1(); >> >>   close cur; >> end >> $$ >>  LANGUAGE 'plpgsql'; >> >> select func2(); >> >> So, cursor's variable is kind of global. I just hope it's a bug and not >> "feature" (at least I haven't found mention of such behaviour in >> documentation) > > It is feature - PLpgSQL engine uses named cursor accessed via SPI API. The name of SPI cursor is generated by cursor variable name. SPI API has zero relation to plpgsql block structure. > > See source code pl_exec.c exec_stmt_open > > Regards > > Pavel > >> -- >> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-bugs -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs