Re: function, that uses different table(names)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Moritz Bayer <moritz(dot)bayer(at)googlemail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: function, that uses different table(names)
Date: 2005-11-02 14:54:52
Message-ID: 5556.1130943292@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Moritz Bayer <moritz(dot)bayer(at)googlemail(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2005-11-02 18:59:30 Re: PGSQL encryption functions
Previous Message Robert Blixt 2005-11-02 14:40:50 Function with dynamic command (EXECUTE) not working