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

calling functions which are stored as values in a table

P: 27
hi... i have this problem... consider the following code... create or replace function sam(in j int) returns int
as
$$
declare
i int;
begin
i := 4;
i= i*j;
return i;
end;
$$
language plpgsql;

create table sam1
(
i varchar
)
insert into sam1 values('sam(j)');


how can i call the function sam which is in the table sam1.. please help
Jul 14 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 700
you can create a plpgsql function
Expand|Select|Wrap|Line Numbers
  1. create or replace function execute2(varchar) returns integer as $$
  2. declare
  3. i integer;
  4. begin
  5.         execute $1 into i;
  6.         return i;
  7. end;
  8. $$ language 'plpgsql';
  9.  
and use it
Expand|Select|Wrap|Line Numbers
  1. select execute2('select '||i) from sam1;
  2.  
Jul 14 '08 #2

P: 27
i am still getting this error...

column "j" does not exist
LINE 1: select sam(j)
Jul 14 '08 #3

Expert 100+
P: 700
i am still getting this error...

column "j" does not exist
LINE 1: select sam(j)
you wrote
Expand|Select|Wrap|Line Numbers
  1. create table sam1
  2. (
  3. i varchar
  4. )
  5.  
you should use 'i' not 'j'.
Jul 14 '08 #4

Post your reply

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