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 C2972D836A for ; Wed, 2 Nov 2005 10:54:50 -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 77230-09 for ; Wed, 2 Nov 2005 14:54:47 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id F3965D82EB for ; Wed, 2 Nov 2005 10:54:48 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jA2EsqNR005557; Wed, 2 Nov 2005 09:54:52 -0500 (EST) To: Moritz Bayer Cc: pgsql-sql@postgresql.org Subject: Re: function, that uses different table(names) In-reply-to: References: Comments: In-reply-to Moritz Bayer message dated "Wed, 02 Nov 2005 14:30:38 +0100" Date: Wed, 02 Nov 2005 09:54:52 -0500 Message-ID: <5556.1130943292@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006] X-Spam-Score: 0.006 X-Spam-Level: X-Archive-Number: 200511/29 X-Sequence-Number: 23281 Moritz Bayer writes: > 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. As noted elsewhere, you could do that by building query strings and EXECUTE'ing them ... but you really ought to rethink your table layout, instead. The SQL-ish way to do this is to combine the tables into one big table with an extra key column that stores whatever condition distinguished the smaller tables in your mind. regards, tom lane