From: Tom Lane <tgl@sss.pgh.pa.us>
To: Moritz Bayer <moritz.bayer@googlemail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: function, that uses different table(names)
Date: Wed, 02 Nov 2005 09:54:52 -0500
Message-ID: <5556.1130943292@sss.pgh.pa.us> (raw)
In-Reply-To: <c244500b0511020530i713d9748j@mail.gmail.com>
References: <c244500b0511020530i713d9748j@mail.gmail.com>
Moritz Bayer <moritz.bayer@googlemail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, moritz.bayer@googlemail.com
Subject: Re: function, that uses different table(names)
In-Reply-To: <5556.1130943292@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox