plpgsql using EXECUTE function

From: "Damjan Pipan" <damjan(dot)pipan(at)xlab(dot)si>
To: <pgsql-general(at)postgresql(dot)org>
Subject: plpgsql using EXECUTE function
Date: 2005-11-10 12:03:15
Message-ID: 20051110115941.76572362581@gw.xlab.si
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 depending on
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.

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2005-11-10 12:12:11 Re: Time trigger
Previous Message Nicolay A Vasiliev 2005-11-10 11:55:01 Re: PL language selection