This kind of thing does work in pltcl but AFAIK you can't specify a table name with a parameter in plpgsql. This may give you the idea:
How can I create a function that will take in two variables and return
an integer, when one of the variables is the tablename ?!I have tried :
create function tst_func(text, varchar(16))
as
'BEGIN
result=select max(history_id)+1 from $1
where client_id = $2;
return result;
END;'
create function myfunc(text,text) returns result as '
set res [spi_exec "select f1 from $1 where f2
= \'$2\']
return $res
' language 'pltcl';
begin:vcard n:Bateman;Kyle tel;fax:801-377-8096 tel;work:801-377-8033x101 x-mozilla-html:FALSE url:www.actiontarget.com org:Action Target Inc adr:;;PO Box 636;Provo;UT;84603;US version:2.1 email;internet:[EMAIL PROTECTED] title:President x-mozilla-cpt:;-15520 fn:Kyle Bateman end:vcard