Re: BUG #14924: Subquery in VALUES inside recursive CTE

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

From: Tom Lane <tgl@sss.pgh.pa.us>
To: christianmduta@gmail.com
Cc: pgsql-bugs@postgresql.org
Date: 2017-11-24T17:06:26Z
Lists: pgsql-bugs
christianmduta@gmail.com writes:
> When working with recursive CTEs, I had the following happen:

Thanks for the report!  Seems not to be specific to CTEs:

regression=# SELECT val.x
  FROM generate_series(1,10) AS s(i),
  LATERAL (
    VALUES
    ((SELECT s.i + 1)), 
    (s.i + 1)
  ) AS val(x)
  WHERE s.i < 10;
ERROR:  SubPlan found with no parent plan

However, simplifying further, this works:

regression=# SELECT val.x
  FROM generate_series(1,10) AS s(i),
  LATERAL (
    VALUES
    ((SELECT 1 + 1)), 
    (s.i + 1)
  ) AS val(x)
  WHERE s.i < 10;

so it looks like it's the LATERAL reference inside the sub-select
that is needed to trigger the bug.

Same results back to 9.3 :-(

			regards, tom lane


Commits

  1. Repair failure with SubPlans in multi-row VALUES lists.

  2. Arrange for ValuesScan to keep per-sublist expression eval state in a