Thread: dynamic functions in plpgsql

dynamic functions in plpgsql

From
Tyler Bye
Date:
I'm currently trying to write a function that will query a table containing
the names of additional functions and then execute one of those functions
after selecting it from the table.

For example.

Say I have a (partial) function pick_fruit(varchar(20),varchar(20))
    type_of_fruit ALIAS FOR $1;
    employee ALIAS FOR $2;
    temprec RECORD;
...

If I SELECT pick_fruit('apple');I would like this function to take the
argument apple and query my pick_fruit_functions table for the  function
named pick_fruit_apple, then execute that function.

let's say that my column name for that list of functions is funcname.

I've tried selecting the function into a RECORD as temprec.  Then I
attempted to reference the result like so,

SELECT temprec.funcname(employee);
...

Is this type of dynamic function binding possible using plpgsql?

I hope this message wasn't too cryptic.

Thanks,
Tyler Bye