Re: Multiple evaluation of single reference to function with out parameters

From: Joel Hoffman <joel(dot)hoffman(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Multiple evaluation of single reference to function with out parameters
Date: 2017-09-23 02:49:22
Message-ID: CAEF8rJs-tCchiE9yF4YN5+810u+8Kf2OCas1g-5RAC2U7RYP1Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Thanks for the response. Here's the documentation reference:

https://www.postgresql.org/docs/9.6/static/rowtypes.html#ROWTYPES-USAGE

Not a bug, but I do think it's very surprising behavior.

Joel

On Fri, Sep 22, 2017 at 5:22 PM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Friday, September 22, 2017, Joel Hoffman <joel(dot)hoffman(at)gmail(dot)com>
> wrote:
>
>> If I create a function with more than one out parameter, and then refer
>> to it inside parentheses as a record, e.g. select (function()).*, the
>> function appears to be evaluated multiple times, once for every column
>> returned. This seems to be true regardless of whether it's defined as
>> volatile or immutable.
>>
>> ...
>
>> As far as I can tell, this behavior has been the same since at least
>> version 8.2 and up through 10 beta 4, but I can't find any references to it
>> and it seems very surprising. It could certainly cause unexpected results
>> if the function has side effects. Is this a bug?
>>
>>
> It is not a bug or likely to be fixed. LATERAL makes the need for
> function invocation in the manner you describe nearly unnecessary and you
> can use OFFSET 0 in other cases to put the function call in a subquery and
> place the (composite).* expressionin the upper-level.
>
> There is a cautionary note somewhere in docs about this. It is a parser
> byproduct. The star gets expanded at parse time to individual and
> independent column names. What happens is exactly what you'd expect if you
> tried to write the query without resorting to using ".*"
>
> David J.
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2017-09-23 03:01:29 Re: Multiple evaluation of single reference to function with out parameters
Previous Message Andrew Dunstan 2017-09-23 01:27:29 Re: BUG #14825: enum type: unsafe use?