Re: Implement targetlist SRFs using ROWS FROM() (was Changed SRF in targetlist handling)

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kevin Grittner <kgrittn@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, Robert Haas <robertmhaas@gmail.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2016-09-02T14:51:15Z
Lists: pgsql-hackers
Kevin Grittner <kgrittn@gmail.com> writes:
> On Fri, Sep 2, 2016 at 9:25 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> ORDER BY is not a useful suggestion when there is nothing
>> you could order by to get the old behavior.

> I'm apparently missing something, because I see a column with the
> header "generate_series" in the result set.

You are apparently only thinking about generate_series and not any
other SRF.  Other SRFs don't necessarily produce outputs that are
in a nice sortable order.  Even for one that does, sorting by it
would destroy the existing behavior:

regression=# select *, generate_series(1,3) from int8_tbl;
        q1        |        q2         | generate_series 
------------------+-------------------+-----------------
              123 |               456 |               1
              123 |               456 |               2
              123 |               456 |               3
              123 |  4567890123456789 |               1
              123 |  4567890123456789 |               2
              123 |  4567890123456789 |               3
 4567890123456789 |               123 |               1
 4567890123456789 |               123 |               2
 4567890123456789 |               123 |               3
 4567890123456789 |  4567890123456789 |               1
 4567890123456789 |  4567890123456789 |               2
 4567890123456789 |  4567890123456789 |               3
 4567890123456789 | -4567890123456789 |               1
 4567890123456789 | -4567890123456789 |               2
 4567890123456789 | -4567890123456789 |               3
(15 rows)

Now you could argue that the ordering of the table rows
themselves is poorly defined, and you'd be right, but that
doesn't change the fact that the generate_series output
has a well-defined repeating sequence.  People might be
relying on that property.

			regards, tom lane


Commits

  1. Remove obsoleted code relating to targetlist SRF evaluation.

  2. Doc: improve documentation of new SRF-in-tlist behavior.

  3. Move targetlist SRF handling from expression evaluation to new executor node.

  4. Don't split up SRFs when choosing to postpone SELECT output expressions.