Received: from www.actarg.com (root@[209.180.91.25]) by hub.org (8.9.3/8.9.3) with ESMTP id SAA51089 for ; Wed, 24 May 2000 18:44:51 -0400 (EDT) (envelope-from kyle@actarg.com) Received: from actarg.com (root@[192.168.2.16]) by www.actarg.com (8.8.7/8.8.7) with ESMTP id PAA07667; Wed, 24 May 2000 15:45:43 -0600 Received: from actarg.com (IDENT:kyle@localhost [127.0.0.1]) by actarg.com (8.9.3/8.9.3) with ESMTP id QAA05907; Wed, 24 May 2000 16:44:44 -0600 Message-ID: <392C5B5C.64CCAA78@actarg.com> Date: Wed, 24 May 2000 16:44:44 -0600 From: Kyle Bateman Organization: Action Target Inc X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Stef telford CC: pgsql-sql@postgresql.org Subject: Clarified Question References: <200005242202.SAA71408@hub.org> Content-Type: multipart/mixed; boundary="------------A3B16ADA8E8EA425BF79BFB9" X-Archive-Number: 200005/125 This is a multi-part message in MIME format. --------------A3B16ADA8E8EA425BF79BFB9 Content-Type: multipart/alternative; boundary="------------9A2C702ED2F9CA68A55306D4" --------------9A2C702ED2F9CA68A55306D4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit > > 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;' > 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: create function myfunc(text,text) returns result as ' set res [spi_exec "select f1 from $1 where f2 = \'$2\'] return $res ' language 'pltcl'; --------------9A2C702ED2F9CA68A55306D4 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit
 
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;'
 

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:

create function myfunc(text,text) returns result as '
    set res [spi_exec "select f1 from $1 where f2 = \'$2\']
    return $res
    ' language 'pltcl';
  --------------9A2C702ED2F9CA68A55306D4-- --------------A3B16ADA8E8EA425BF79BFB9 Content-Type: text/x-vcard; charset=us-ascii; name="kyle.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Kyle Bateman Content-Disposition: attachment; filename="kyle.vcf" 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:kyle@actiontarget.com title:President x-mozilla-cpt:;-15520 fn:Kyle Bateman end:vcard --------------A3B16ADA8E8EA425BF79BFB9--