Re: function, that uses different table(names)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: function, that uses different table(names)
Дата
Msg-id 5556.1130943292@sss.pgh.pa.us
обсуждение исходный текст
Ответ на function, that uses different table(names)  (Moritz Bayer <moritz.bayer@googlemail.com>)
Список pgsql-sql
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Robert Blixt"
Дата:
Сообщение: Function with dynamic command (EXECUTE) not working
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: PGSQL encryption functions