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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: 德哥 <digoal(at)126(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14463: refcursor cann't used with array or variadic parameter?
Date: 2016-12-13 16:16:43
Message-ID: CAFj8pRAO29VqqH13aWK1YPyRiL1VZvdS+uKzFB-S6S20ukgtug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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(at)126(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Análise Sistema Ágile 2016-12-13 16:32:16 Problems about FUNCTIONS
Previous Message digoal 2016-12-13 15:25:48 BUG #14463: refcursor cann't used with array or variadic parameter?