Re: Function returning 2 columns evaluated twice when both columns are needed - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Function returning 2 columns evaluated twice when both columns are needed
Date
Msg-id b42b73150910201712x4b6ce6ccsb79870e4c6cfad15@mail.gmail.com
Whole thread Raw
In response to Re: Function returning 2 columns evaluated twice when both columns are needed  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Function returning 2 columns evaluated twice when both columns are needed
List pgsql-general
On Tue, Oct 20, 2009 at 5:12 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
>> [ shrug... ]  There are other possible reasons why the planner would
>> fail to flatten a subquery, but none of them apply to the example you
>> showed.  And your example function *was* VOLATILE, by default.
>
> I checked this on 8.5 and function is evaluated more time although is immutable.
>
> postgres=# create or replace function foo(out a int, out b int)
> returns record as $$
> begin
> raise notice 'start foo';
> a := 10; b := 20;
> return;
> end;
> $$ language plpgsql immutable;
> CREATE FUNCTION
>
> postgres=# select (foo()).*;

This is because select (func()).* is expanded to mean:
select func(f1), func(f2) ... func(fn);

This is a general issue with '*' because in postgres it means:
'evaluate me for each field of me', not 'return all fields of me'. I
don't think our behavior in this regard is correct (afaict i'm in the
minority though).

merlin

pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Function returning 2 columns evaluated twice when both columns are needed
Next
From: John
Date:
Subject: Re: multi-company design/structure ?