Passing tablename as argument into function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gouse
    New Member
    • Feb 2007
    • 18

    Passing tablename as argument into function

    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
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Code:
    Select sum(salary) from strTable
    to do that you have to put execute clause (it is a dynamic query).

    Comment

    Working...