Thread: plpgsql using EXECUTE function

plpgsql using EXECUTE function

From
"Damjan Pipan"
Date:
Hi,

I would like to have one function in plpgsql which is gen_func. From this function I would like to call other functions
dependingon 
the input parameters of gen_func - lets say f1 and f2. Parameters to f1 or f2 are text, refcursor and text[].

I tried to use EXECUTE but the problem is how to get refcursor and text[] to sql string.

After quite some time I found that if you do

DECLARE
cur1 refcursor;
arr1 text[];
tmp text;
...
BEGIN
...
tmp = cur1;
tmp = arr1;
END;

will get the name of the cursor to tmp or format arr1 to text representation or would quote text strings.

Then I could constructed the sql like
sql = 'SELECT ' || f1 || '(\'' || tmp .....
and then
EXECUTE sql;

Is this the right way?

Should I quote_ident function name f1 or f2?
Is it the supposed action of tmp=arr1 to quote_literal its values?

Thank you for zour replies.