Re: Dynamic binding in plpgsql function
От | Dmitriy Igrishin |
---|---|
Тема | Re: Dynamic binding in plpgsql function |
Дата | |
Msg-id | AANLkTi=OPgTtR983HeK7Q-=_rK1npggmJHnx_kt_wVOh@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Dynamic binding in plpgsql function (Merlin Moncure <mmoncure@gmail.com>) |
Ответы |
Re: Dynamic binding in plpgsql function
|
Список | pgsql-general |
2011/3/2 Merlin Moncure <mmoncure@gmail.com>
On Tue, Mar 1, 2011 at 5:17 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:another way if you are willing to write some C is to wrap and expose
> Hello
>
> 2011/3/2 Pierre Racine <Pierre.Racine@sbf.ulaval.ca>:
>> Hi,
>>
>> I would like to write a generic plpgsql function with a text parameter being a callback function name so that my general function can call this callback function. e.g.:
>>
>> CREATE OR REPLACE FUNCTION ST_MyCallbackFunction(y int)
>> RETURNS int AS $$
>> DECLARE
>> BEGIN
>> RETURN someCalculationBasedOnY;
>> END;
>> $$ LANGUAGE 'plpgsql';
>>
>> CREATE OR REPLACE FUNCTION ST_MyGeneralFunction(callback text)
>> RETURNS SETOF geomval AS $$
>> DECLARE
>> x integer;
>> y integer;
>> BEGIN
>> y := somecalculation;
>> x := 'callback'(y); --This is what I need
>
> EXECUTE 'SELECT ' || callback || '($1)' USING y INTO x;
>
> there are no other way than EXECUTE
>
> attention - there is a sql injection risk
OidFunctionCall1 so it takes oid of function you want to call.
As always, Merlin shows the uncommon thinking! :-)
Respect!
Respect!
merlin
--Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
// Dmitriy.
В списке pgsql-general по дате отправления: