Executing function dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prdola
    New Member
    • Oct 2008
    • 2

    Executing function dynamically

    Hi,
    I have a table with function names and some other flags where to run them. Sth like this table called PROCESS

    Code:
    name    run_daily   run_monthly
    func1       Y                   N
    func2       Y                   Y
    func3       N                   Y
    ...
    then I have function that should execute selected functions sth like

    Code:
    create or replace function execute_process() returns void as
    $$
    declare
      c_process refcursor; 
      r_process dwh_loader.process%ROWTYPE;
      v_stmt varchar(200);
    begin
      OPEN c_process FOR SELECT * 
                           FROM process 
                          WHERE run_daily = 'Y';
      LOOP
        fetch c_process into r_process;
        -- 
        IF  NOT FOUND THEN
            EXIT;  -- exit loop
        END IF;    
        v_stmt := 'perform '|| r_process.name ||';';
        --
        execute v_stmt;
      END LOOP;
      --
      return;
    end;
    $$language plpgsql;
    This is pretty much how I would handle this situation in Oracle, but Postgre does not allow
    execute 'perform....'

    Any suggestion how to resolve this issue?

    Karel
    Last edited by eWish; Oct 22 '08, 10:05 PM. Reason: Please use code tags
  • prdola
    New Member
    • Oct 2008
    • 2

    #2
    Suggestion is to use

    execute 'command string' into variable;

    like here
    http://www.postgresql. org/docs/8.3/static/plpgsql-statements.html #PLPGSQL-STATEMENTS-EXECUTING-DYN

    Comment

    Working...