Connecting Tech Pros Worldwide Forums | Help | Site Map

Passing tablename as argument into function

Newbie
 
Join Date: Feb 2007
Posts: 13
#1: Aug 26 '08
Create or replace function Test(strTable in text) return bigint as
$$
declare
intSum bigint;
begin
intSum:=(Select sum(salary) from strTable);
return intSum;
end;
$$
language plpgsql;

select Test('Employee');

I want to pass Table name as a argument into function and execute select statement on this table
I run this function error is occure

Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 293
#2: Aug 26 '08

re: Passing tablename as argument into function


Expand|Select|Wrap|Line Numbers
  1. Select sum(salary) from strTable
  2.  
to do that you have to put execute clause (it is a dynamic query).
Reply