From: | Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | implicit vs. explicit RETURN when OUT is used |
Date: | 2008-01-04 08:38:35 |
Message-ID: | 20080104093835.39212700@webthatworks.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | mljv | 2008-01-04 08:44:46 | server process (PID 27884) was terminated by signal 4 (SIGILL) |
Previous Message | Marko Kreen | 2008-01-04 08:35:38 | Re: Feature request: NOTIFY enhancement |