Bug reference: 14275
Logged by: Oleg Klimovich
Email address: kli...@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)
--
Sent via pgsql-bugs mailing list (pgsql...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-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)
2016-08-04 15:03 GMT+02:00 kli...@tut.by <kli...@tut.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.