Re: Undocumented array_val[generate_series(...)] functionality? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Undocumented array_val[generate_series(...)] functionality?
Date
Msg-id CAKFQuwY=4BBQ9iMarAk4MFQdZ0u-xXvW=P25aHChX4b7MdXmwA@mail.gmail.com
Whole thread Raw
In response to Re: Undocumented array_val[generate_series(...)] functionality?  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Undocumented array_val[generate_series(...)] functionality?  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-general
On Sun, Jul 11, 2021 at 6:06 PM David Rowley <dgrowleyml@gmail.com> wrote:
select abs(generate_series(-3,-1));

abs() is simply called once per output value of the generate_series
SRF.  That seems fairly equivalent to me to what's going on in your
example case.


Fair point.  Both of these are premised on two related facts:

One, the select generate_series(1,3) function call causes multiple rows to be generated where there would usually be only one.  In short, SRF function calls and non-SRF function calls exhibit different behaviors on the output.

Two, composition results in an inside-to-outside execution order: the SRF is evaluated first, the additional rows added, then the outer function (abs or the subscript function respectively in these examples) is evaluated for whatever rows are now present in the result.

Is the above something one can learn from our documentation?

Is this syntax we are discouraging users from using and thus intentionally not documenting it?  I do get this impression but, frankly, given the utility of " [ generate_series(...) ] " I find it hard to recommend something different to get the same result yet don't have a place to point and say "here is how and why it works".

David J.


pgsql-general by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: Removing a subscription that does not exist
Next
From: Laurenz Albe
Date:
Subject: Re: What to look for when excessively long commits