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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: "klimych(at)tut(dot)by" <klimych(at)tut(dot)by>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
Date: 2016-08-04 14:10:20
Message-ID: CAFj8pRA3Y8xRhuOY1twUN2X_gt0dTtp0GHodiTmYi9rDpVY6XA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

2016-08-04 15:03 GMT+02:00 klimych(at)tut(dot)by <klimych(at)tut(dot)by>:

> 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)
>

I agree so this is little bit strange - it looks like workaround of some
historical limit of SPI. It is too late to change. But it has some
advantage. Postgres can't to pass parameters by ref. With named cursors you
can do it.

Regards

Pavel

>
> 03.08.2016, 16:03, "Andrew Gierth" <andrew(at)tao11(dot)riddles(dot)org(dot)uk>:
> >>>>>> "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)
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2016-08-04 14:23:53 Re: BUG #14275: cursor's variable in pgsql doesn't respect scope
Previous Message David G. Johnston 2016-08-04 14:00:31 Re: [BUGS] Return value error of‘to_timestamp’