Search Postgresql Archives

implicit vs. explicit RETURN when OUT is used

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux