Hello 2011/3/2 Pierre Racine <Pierre.Racine@xxxxxxxxxxxxx>: > 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 regards Pavel Stehule > Â Â Â ÂRETURN x; > Â ÂEND; > Â Â$$ LANGUAGE 'plpgsql'; > > I don't want to do an EXECUTE statement since I have no table to put after the FROM clause. I want to assign the resulting value directly to a variable like in my example. > > Can I/How can I achieve this? > > Thanks, > > Pierre > > > -- > Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-general > -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general