Functiion Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jesmi
    New Member
    • Apr 2007
    • 53

    #1

    Functiion Problem

    hi all,

    i have a table with three columns.
    tran_event_cd, event_cd,party_ cd.
    can i pass the column name in the function.

    Code:
    create or replace function fn_one(int8,int8)
    returns setof tbl_one as 
    '
    declare 
    r tbl_one%rowtype;
    a alias for $1;
    b alias for $2;
    begin
     for r in select tran_event_cd, event_cd,party_cd
     from tran_event where $1=$2
    loop
    return next r;
    end loop;
    return ''a'';
    end'
    language 'plpgsql' volatile;
    where $1 is field name just like event_cd and $2 is its value.
    is it possible to do so.
    plz any help is appreciated.
    TIA
  • michaelb
    Recognized Expert Contributor
    • Nov 2006
    • 534

    #2
    I don't think you can pass column name to the function.

    As a side note if you were to pass the column name the first argument in the function would've been declared as type name, or varchar, not the integer.

    Another problem there is on line 14: return ''a'';
    You cannot return anything when function returns a rowset - this line should be just return;

    Comment

    Working...