From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: klimych@tut.by
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
Date: Wed, 03 Aug 2016 14:03:22 +0100
Message-ID: <874m72ggi4.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <20160803095301.1420.50016@wrigleys.postgresql.org>
References: <20160803095301.1420.50016@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
>>>>> "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: andrew@tao11.riddles.org.uk, klimych@tut.by
Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
In-Reply-To: <874m72ggi4.fsf@news-spur.riddles.org.uk>
References: <20160803095301.1420.50016@wrigleys.postgresql.org> <874m72ggi4.fsf@news-spur.riddles.org.uk>
* 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