plpgsql using EXECUTE function - Mailing list pgsql-general

From Damjan Pipan
Subject plpgsql using EXECUTE function
Date
Msg-id 20051110115941.76572362581@gw.xlab.si
Whole thread Raw
List pgsql-general
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.




pgsql-general by date:

Previous
From: "Helge Elvik"
Date:
Subject: Compiling libpq on Windows
Next
From: juleni@livetrade.cz
Date:
Subject: TIMESTAMP vs TIMESTAMP WITHOUT TIME ZONE