Re: Undocumented array_val[generate_series(...)] functionality?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Undocumented array_val[generate_series(...)] functionality?
Date: 2021-07-12 01:39:21
Message-ID: CAKFQuwY=4BBQ9iMarAk4MFQdZ0u-xXvW=P25aHChX4b7MdXmwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jul 11, 2021 at 6:06 PM David Rowley <dgrowleyml(at)gmail(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2021-07-12 05:35:02 Re: Why can't I drop a tablespace?
Previous Message Kyotaro Horiguchi 2021-07-12 01:38:01 Re: Removing a subscription that does not exist