Lists: | pgsql-sql |
---|
From: | "Owen Jacobson" <ojacobson(at)osl(dot)com> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: OUT parameter |
Date: | 2006-03-22 22:39:13 |
Message-ID: | 144D12D7DD4EC04F99241498BB4EEDCC25EAD1@nelson.osl.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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's not a good idea to modify out parameters partway; programmers (myself included) have this nasty habit of assuming, rightly or wrongly, that a failed function call won't have destroyed the parameters.
If you can't ensure you'll always complete, use locals.
-Owen
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Owen Jacobson" <ojacobson(at)osl(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: OUT parameter |
Date: | 2006-03-23 02:47:31 |
Message-ID: | 27322.1143082051@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
> Daniel Caune wrote:
>> Is there any suggestion against using OUT parameter for local
>> calculation such as using a local variable?
In plpgsql (at least in the current implementation) an OUT parameter is
pretty much just a local variable, and so there's no efficiency argument
against using it as a temporary. Whether you consider this good style
is a matter of opinion.
"Owen Jacobson" <ojacobson(at)osl(dot)com> writes:
> I'd say there's no problem with this, PROVIDED you can ensure you'll
> never abort before completing the computation.
Not really an issue in Postgres: we do not support pass-by-reference
parameters and are unlikely to start doing so. There isn't any way
that you can affect locals of a calling procedure before you return.
regards, tom lane