Connecting Tech Pros Worldwide Help | Site Map

Executing function dynamically

Newbie
 
Join Date: Oct 2008
Posts: 2
#1: Oct 17 '08
Hi,
I have a table with function names and some other flags where to run them. Sth like this table called PROCESS

Expand|Select|Wrap|Line Numbers
  1. name    run_daily   run_monthly
  2. func1       Y                   N
  3. func2       Y                   Y
  4. func3       N                   Y
  5. ...
then I have function that should execute selected functions sth like

Expand|Select|Wrap|Line Numbers
  1. create or replace function execute_process() returns void as
  2. $$
  3. declare
  4.   c_process refcursor; 
  5.   r_process dwh_loader.process%ROWTYPE;
  6.   v_stmt varchar(200);
  7. begin
  8.   OPEN c_process FOR SELECT * 
  9.                        FROM process 
  10.                       WHERE run_daily = 'Y';
  11.   LOOP
  12.     fetch c_process into r_process;
  13.     -- 
  14.     IF  NOT FOUND THEN
  15.         EXIT;  -- exit loop
  16.     END IF;    
  17.     v_stmt := 'perform '|| r_process.name ||';';
  18.     --
  19.     execute v_stmt;
  20.   END LOOP;
  21.   --
  22.   return;
  23. end;
  24. $$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
Newbie
 
Join Date: Oct 2008
Posts: 2
#2: Oct 23 '08

re: Executing function dynamically


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
Reply