Re: BUG #14275: cursor's variable in pgsql doesn't respect scope

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: klimych(at)tut(dot)by
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
Date: 2016-08-03 13:03:22
Message-ID: 874m72ggi4.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>>>>> "klimych" == klimych <klimych(at)tut(dot)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)

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2016-08-03 13:03:53 Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
Previous Message klimych 2016-08-03 09:53:01 BUG #14275: cursor's variable in pgsql doesn't respect scope