Re: OUT parameter - Mailing list pgsql-sql

From Owen Jacobson
Subject Re: OUT parameter
Date
Msg-id 144D12D7DD4EC04F99241498BB4EEDCC25EAD1@nelson.osl.com
Whole thread Raw
In response to OUT parameter  ("Daniel Caune" <daniel.caune@ubisoft.com>)
Responses Re: OUT parameter
List pgsql-sql
Daniel Caune wrote:

> Is there any suggestion against using OUT parameter for local
> calculation such as using a local variable?
>
> CREATE OR REPLACE FUNCTION foo(a IN int,
>                                b1 OUT int,
>                                b2 OUT int)
> AS $$
> BEGIN
>   FOR (...) LOOP
>     b1 = (...);
>     b2 = (...);
>   END LOOP;
> END;
> $$ LANGUAGE PLPGSQL;

I'd say there's no problem with this, PROVIDED you can ensure you'll never abort before completing the computation.
It'snot a good idea to modify out parameters partway; programmers (myself included) have this nasty habit of assuming,
rightlyor wrongly, that a failed function call won't have destroyed the parameters. 

If you can't ensure you'll always complete, use locals.

-Owen


pgsql-sql by date:

Previous
From: "Daniel Caune"
Date:
Subject: OUT parameter
Next
From: "Christian Paul B. Cosinas"
Date:
Subject: Re: Function Parameters in GROUP BY clause cause errors