Thread: plpgsql ?
Hi all, i have a question 'plpgsql' my code CREATE FUNCTION autono (text,text) RETURNS text AS ' DECLARE a1 ALIAS FOR $1; a2 ALIAS FOR $1; ret_val text; BEGIN select tna into ret_val from a1 where pamt_no=a2; RETURN ret_val; END;' LANGUAGE 'plpgsql' error run " select tna into ret_val from a1 where pamt_no=a2; " help me ,thanks
> CREATE FUNCTION autono (text,text) RETURNS text AS ' > DECLARE > a1 ALIAS FOR $1; > a2 ALIAS FOR $1; > ret_val text; > BEGIN > select tna into ret_val from a1 where pamt_no=a2; > > RETURN ret_val; > END;' LANGUAGE 'plpgsql' > > > error run " select tna into ret_val from a1 where pamt_no=a2; " You cannot give a table name as an argument. You should write different SELECTs for different tables, like this: if a1 = ''dummy1'' then select tna into ret_val from dummy1 where pamt_no=a2; end if; if a1 = ''dummy2'' then select tna into ret_val from dummy2 where pamt_no=a2; end if; ... And so on. Unfortunately... :-) Zoltan
Hi, there, see following. Jie LIANG Internet Products Inc. 10350 Science Center Drive Suite 100, San Diego, CA 92121 Office:(858)320-4873 jliang@ipinc.com www.ipinc.com On Wed, 20 Dec 2000, guard wrote: > Hi all, > > i have a question 'plpgsql' > > my code > > CREATE FUNCTION autono (text,text) RETURNS text AS ' > DECLARE > a1 ALIAS FOR $1; > a2 ALIAS FOR $1; <== $2 ?? > ret_val text; > BEGIN > select tna into ret_val from a1 where pamt_no=a2; > -- I think that table name cannot use parameter anyway in plpgsql. > RETURN ret_val; > END;' LANGUAGE 'plpgsql' > > > error run " select tna into ret_val from a1 where pamt_no=a2; " > help me ,thanks > > > > >