BUG #14924: Subquery in VALUES inside recursive CTE

christianmduta@gmail.com

From: christianmduta@gmail.com
To: pgsql-bugs@postgresql.org
Cc: christianmduta@gmail.com
Date: 2017-11-24T12:08:36Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      14924
Logged by:          Christian Duta
Email address:      christianmduta@gmail.com
PostgreSQL version: 10.1
Operating system:   macOS High Sierra 10.13.1 
Description:        

When working with recursive CTEs, I had the following happen:

Evaluating the following

-- List numbers from 1 to 10.
WITH RECURSIVE
steps(i) AS (
  SELECT 1
    UNION
  SELECT val.x
  FROM steps AS s,
  LATERAL (
    VALUES
    ((SELECT s.i + 1)), 
    (s.i + 1)
  ) AS val(x)
  WHERE s.i < 10
)
SELECT *
FROM steps;

results in

ERROR:  XX000: SubPlan found with no parent plan
LOCATION:  ExecInitExprRec, execExpr.c:1013


Commits

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

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