X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CFE2FD786C for ; Wed, 2 Nov 2005 09:30:35 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44847-05 for ; Wed, 2 Nov 2005 13:30:32 +0000 (GMT) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.198]) by svr1.postgresql.org (Postfix) with ESMTP id 54DEED7221 for ; Wed, 2 Nov 2005 09:30:33 -0400 (AST) Received: by xproxy.gmail.com with SMTP id t11so197799wxc for ; Wed, 02 Nov 2005 05:30:38 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=googlemail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=GoXoxFovGB5CDdzKpFgvgwA3bhtLQep1vZ1rJ7IDGQvr7d43mSwc8Ehs/tg+cjs2CcMRzrUsbbmoOUZo8xyoDQMT3ccqBijEiFua4WOVljEy6zY10RtkZ9H7UrZkGqu+wIU9vrcDtJOhbXyHlcNKtStDx1D10wSuSmj7Pi1JYJ8= Received: by 10.65.212.14 with SMTP id o14mr1895055qbq; Wed, 02 Nov 2005 05:30:38 -0800 (PST) Received: by 10.64.232.1 with HTTP; Wed, 2 Nov 2005 05:30:38 -0800 (PST) Message-ID: Date: Wed, 2 Nov 2005 14:30:38 +0100 From: Moritz Bayer To: pgsql-sql@postgresql.org Subject: function, that uses different table(names) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2697_19719563.1130938238242" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.333 required=5 tests=[HTML_MESSAGE=0.001, RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.333 X-Spam-Level: * X-Archive-Number: 200511/21 X-Sequence-Number: 23273 ------=_Part_2697_19719563.1130938238242 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello group, I've a bunch of tables, which have just about the same name. They are just iterated like this: tbl_table1 tbl_table2 tbl_table3 ... They all have the same field, but different data. Now I'm wondering, if I have to write functions for every table, although they perform the same operation? Or is it possible to pass an integer parameter to the function, use it to put the right tablename together and perform the operation. This would something look like this: CREATE OR REPLACE function getmaxuserid(integer) RETURNS integer AS' DECLARE tmp_tmp_tmp_table varchar(100); DECLARE tmp_table varchar(100); DECLARE tmp_tmp_table varchar(100); DECLARE live_table varchar(100); DECLARE i_return integer; BEGIN --live_table :=3D ''tbl_highscore_app'' || cast($1 as varchar); SELECT max(userid) FROM ''tbl_highscore_app'' || cast($1 as varchar); return(0); END; 'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER; I don't know if this is good practise, but I'm trying to create a function which gets an integer. ------=_Part_2697_19719563.1130938238242 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello group,

I've a bunch of tables, which have just about the same name. They are just = iterated like this:

tbl_table1
tbl_table2
tbl_table3
...

They all have the same field, but different data.

Now I'm wondering, if I have to write functions for every table,  alth= ough they perform the same operation?
Or is it possible to pass an integer parameter to the function, use it to put the right tablename together and perform the operation.

This would something look like this:

CREATE OR REPLACE function getmaxuserid(integer) RETURNS integer AS'
DECLARE tmp_tmp_tmp_table varchar(100);
       DECLARE tmp_table varchar(100);
       DECLARE tmp_tmp_table varchar(100);        DECLARE live_table varchar(100);
       DECLARE i_return integer;
BEGIN
     --live_table :=3D ''tbl_highscore_app'' || cast($1= as varchar);
     SELECT   max(userid) FROM ''tbl_highscor= e_app'' || cast($1 as varchar);
    
    

 return(0);
 END;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;


I don't know if this is good practise, but I'm trying to create a function = which gets an integer.


------=_Part_2697_19719563.1130938238242--