Обсуждение: function that returns dynamicly created table

Поиск
Список
Период
Сортировка

function that returns dynamicly created table

От
Michal Holečka
Дата:
Hi everybody

I am pretty new to postgre and dunno if something like this is possible
in PL/pgSQL

I would like to create function create_table(integer[]) that returns
dynamically created table. Table is composed of  several tables which
are left joined together. How many tables are joined is said by function
argument - integer field..

example :

field[] = {1,1,1} means function should return      table1 left join
(table 2 leftjoin table 3);

field[]=  {1,0,0} means function should return     table 1;

if it is possible then pls let mi now how.....

thanx a lot
miso




Re: function that returns dynamicly created table

От
Josh Berkus
Дата:
Michal,

> I would like to create function create_table(integer[]) that returns
> dynamically created table. Table is composed of  several tables which
> are left joined together. How many tables are joined is said by function
> argument - integer field..

It's possible in 7.3 and 7.4 but not in earlier versions of PostgreSQL.  See:
http://techdocs.postgresql.org/guides/SetReturningFunctions

WHY you would want to do such a thing is a question which is beyond me
entirely.

--
Josh Berkus
Aglio Database Solutions
San Francisco

Re: function that returns dynamicly created table

От
Nabil Sayegh
Дата:
Josh Berkus wrote:
> Michal,
>
>
>>I would like to create function create_table(integer[]) that returns
>>dynamically created table. Table is composed of  several tables which
>>are left joined together. How many tables are joined is said by function
>>argument - integer field..
>
>
> It's possible in 7.3 and 7.4 but not in earlier versions of PostgreSQL.  See:
> http://techdocs.postgresql.org/guides/SetReturningFunctions
>
> WHY you would want to do such a thing is a question which is beyond me
> entirely.

Makes perfect sense to me, if he's trying to create tables based on meta data in another table.

--
  e-Trolley Sayegh & John, Nabil Sayegh
  Tel.: 0700 etrolley /// 0700 38765539
  Fax.: +49 69 8299381-8
  PGP : http://www.e-trolley.de