From: klimych@tut.by <klimych@tut.by>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
Date: Thu, 04 Aug 2016 16:03:42 +0300
Message-ID: <634371470315822@web8h.yandex.ru> (raw)
In-Reply-To: <874m72ggi4.fsf@news-spur.riddles.org.uk>
References: <20160803095301.1420.50016@wrigleys.postgresql.org>
<874m72ggi4.fsf@news-spur.riddles.org.uk>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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" <andrew@tao11.riddles.org.uk>:
>>>>>> "klimych" == klimych <klimych@tut.by> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: klimych@tut.by, andrew@tao11.riddles.org.uk
Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
In-Reply-To: <634371470315822@web8h.yandex.ru>
References: <20160803095301.1420.50016@wrigleys.postgresql.org> <874m72ggi4.fsf@news-spur.riddles.org.uk> <634371470315822@web8h.yandex.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox