Re: BUG #14463: refcursor cann't used with array or variadic parameter?

Pavel Stehule <pavel.stehule@gmail.com>

From: Pavel Stehule <pavel.stehule@gmail.com>
To: 德哥 <digoal@126.com>
Cc: "pgsql-bugs@postgresql.org" <pgsql-bugs@postgresql.org>
Date: 2016-12-13T16:16:43Z
Lists: pgsql-bugs
Hi

It is not a bug - it is feature. PLpgSQL statements doesn't expect a
expression on some places.


2016-12-13 16:25 GMT+01:00 <digoal@126.com>:

> CREATE FUNCTION myfunc(variadic ref refcursor[]) RETURNS SETOF
> refcursor AS $
> begin
>  open ref[1] for select * from pg_class;
>  return next ref[1];
>  open ref[2] for select * from pg_class;
>  return next ref[2];
> end;
> $ lANGUAGE plpgsql;
>

There is a workaround

CREATE FUNCTION myfunc(variadic ref refcursor[]) RETURNS SETOF
refcursor AS $$ declare r refcursor;
begin r = ref[1];
 open r for select * from pg_class;
 return next ref[1]; r = ref[2];
 open r for select * from pg_class;
 return next ref[2];
end;
$$ lANGUAGE plpgsql;

Personally, I have not any idea what do you do. Maybe a C extension can
works better for you - PLpgSQL is static strict language. When you use too
dynamic code, the result can be hardly maintainable.

Regards

Pavel Stehule

Commits

  1. Improve handling of array elements as getdiag_targets and cursor_variables.