Letting a function return multiple columns instead of a single complex one

Поиск
Список
Период
Сортировка
От A.j. Langereis
Тема Letting a function return multiple columns instead of a single complex one
Дата
Msg-id 003301c5fabd$900421c0$6500a8c0@aarjan2
обсуждение исходный текст
Ответы Re: Letting a function return multiple columns instead of a single complex one  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Letting a function return multiple columns instead of a single complex ones  (Volkan YAZICI <yazicivo@ttnet.net.tr>)
Список pgsql-general
Dear all,
 
I have two questions: fist of all, is there any function in pg like oracle's rownum?
 
secondly, I wonder how it is possible to let a function return a dataset with different columns instead of a single, complex, one.
 
create table foo (a int, b int);
 
insert into foo (a,b) values (1,2);
insert into foo (a,b) values (2,3);
 
create or replace function get_a_foo(a int)
 returns setof foo as
$$
select * from foo where a = $1;
$$
language sql volatile;
 
something like "select get_a_foo(1);" would return:
 get_a_foo
-----------
 (1,2)
(1 row)
 
whereas "select * from get_a_foo(1);" will retunr:
 a | b
---+---
 1 | 2
(1 row)
The problem I am facing is that I will execute this function as part of another query where the parameter will be one of the columns of another table. Something like: "select bar.*, get_a_foo(c) from bar". I need the result set to be like a table, because I'll have to use it later in another query.
The whole construction works fine if there would be only one column in the resultset of the query, something that is not the case here.
 
Anyone any suggestion?
 
Yours Aarjan

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

Предыдущее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: deadlock on the same relation
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Letting a function return multiple columns instead of a single complex one