implicit vs. explicit RETURN when OUT is used

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема implicit vs. explicit RETURN when OUT is used
Дата
Msg-id 20080104093835.39212700@webthatworks.it
обсуждение исходный текст
Ответы Solution: implicit vs. explicit RETURN when OUT is used  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Re: implicit vs. explicit RETURN when OUT is used  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
I've read this

CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod
int)
AS $$
BEGIN
    sum := x + y;
    prod := x * y;
END;
$$ LANGUAGE plpgsql;

at

http://www.postgresql.org/docs/8.1/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-ALIASES

what if I need explicit RETURN to get out of the function if I don't
want to create a type and still have control of the types of the
returned values (that means avoiding any*)?

eg.

if(found) then
  RETURN Afunction();
else
  RETURN Bfunction();
end if;

currently I solved the issue this way:

create or replace function testA(out _BasketID1 int, out _BasketID2
int) as $$
begin
    _BasketID1:=1;
    _BasketID2:=2;
    return;
end;
$$ language plpgsql;

create or replace function testB(out _BasketID1 int, out _BasketID2
int) as
$$
begin
    select into _BasketID1,_BasketID2  * from testA();
    return;
end;
$$ language plpgsql;


But when I switch to

select into _BasketID1,_BasketID2 _BasketID1,_BasketID2 from testA();

nothing get back from testB().

That obliges me to match returning parameters, that may not always be
the case.

Any other way to return *controlled* composite types without
declaring a composite type explicitly?

thx


--
Ivan Sergio Borgonovo
http://www.webthatworks.it


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

Предыдущее
От: "Albe Laurenz"
Дата:
Сообщение: Re: Can't make backup
Следующее
От: "Marko Kreen"
Дата:
Сообщение: Re: Feature request: NOTIFY enhancement