Re: function returning result set of varying column
От | Pavel Stehule |
---|---|
Тема | Re: function returning result set of varying column |
Дата | |
Msg-id | 162867790806030713p284b3d72k137fb729a4a28387@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: function returning result set of varying column ("maria s" <psmg01@gmail.com>) |
Ответы |
Re: function returning result set of varying column
|
Список | pgsql-sql |
2008/6/3 maria s <psmg01@gmail.com>: > Hi Ivan, > If I have to know the column names then I can't use the Functions. > As I said before, the columns will vary. or As Pavel Stehule said > I will use arrays. > > Is anyone can show an example of returning a record with string and array? postgres=# create or replace function foo(int) returns text[] as $$select array(select 'kuku' || i from generate_series(1,$1) g(i))$$ language sql; CREATE FUNCTION Time: 69,730 ms postgres=# select foo(10); foo ----------------------------------------------------------------{kuku1,kuku2,kuku3,kuku4,kuku5,kuku6,kuku7,kuku8,kuku9,kuku10} (1 row) Time: 1,739 ms postgres=# select foo(5); foo ---------------------------------{kuku1,kuku2,kuku3,kuku4,kuku5} (1 row) Time: 1,274 ms > > Thanks, > Maria > > On Tue, Jun 3, 2008 at 9:57 AM, Ivan Sergio Borgonovo <mail@webthatworks.it> > wrote: >> >> On Tue, 3 Jun 2008 09:41:27 -0400 >> "maria s" <psmg01@gmail.com> wrote: >> >> > Thanks for all your replies. >> > >> > Actually I don't know the number of columns that I am going to >> > return. >> > >> > I have 2 tables. For a single entry E1 in one table(t1), I have >> > to fetch all the matching entries for E1 from the other >> > table(t2), K1,..Kn. and finally the function should return E1, >> > K1..Kn. So I don't know the number of columns that I am going to >> > get. >> > >> > Is it possible to write a function that returns this kind of >> > result? >> >> Up to my knowledge as Bart wrote in pl/pgsql you'll have to specify >> somewhere the return type: in the function or in the select calling >> the function. >> If you use sql (not pl/pgsql) function you shouldn't be obliged to >> specify the return type. >> But I haven't written enough sql function to actually remember how >> it works. >> >> If you post your tentative sql it could give us more clue. >> >> -- >> Ivan Sergio Borgonovo >> http://www.webthatworks.it >> >> >> -- >> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) >> To make changes to your subscription: >> http://www.postgresql.org/mailpref/pgsql-sql > >
В списке pgsql-sql по дате отправления: