By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Executing function dynamically

P: 2
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
Oct 17 '08 #1
Share this Question
Share on Google+
1 Reply


P: 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
Oct 23 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.