Re: BUG #18536: Using WITH inside WITH RECURSIVE triggers a "shouldn't happen" error

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #18536: Using WITH inside WITH RECURSIVE triggers a "shouldn't happen" error
Дата
Msg-id 2781444.1720969777@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #18536: Using WITH inside WITH RECURSIVE triggers a "shouldn't happen" error  (PG Bug reporting form <noreply@postgresql.org>)
Ответы Re: BUG #18536: Using WITH inside WITH RECURSIVE triggers a "shouldn't happen" error
Список pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> The following query:
> WITH RECURSIVE t(n) AS (
>     WITH t1 AS (SELECT 1 FROM t) SELECT 1
>     UNION
>     SELECT 1 FROM t1)
> SELECT * FROM t;

That should throw an error, certainly: it's not a valid recursive
structure.  (Since the inner WITH clause spans the whole
"SELECT 1 UNION SELECT 1 FROM t1" structure, we don't have a top-
level UNION anymore.)  But it shouldn't throw this error:

> ERROR:  XX000: missing recursive reference
> LOCATION:  checkWellFormedRecursion, parse_cte.c:896

We do get the right behaviors for WITHs that are down inside one
side or the other of the UNION:

WITH RECURSIVE t(n) AS (
    (WITH t1 AS (SELECT 1 FROM t) SELECT 1 FROM t1)
    UNION
    SELECT 1)
SELECT * FROM t;
ERROR:  recursive reference to query "t" must not appear within its non-recursive term
LINE 2:     (WITH t1 AS (SELECT 1 FROM t) SELECT 1 FROM t1)
                                       ^

WITH RECURSIVE t(n) AS (
  SELECT 1
  UNION
  (WITH t1 AS (SELECT 1 FROM t) SELECT 1 FROM t1))
SELECT * FROM t;
 n
---
 1
(1 row)

I think the case you show should be throwing

ERROR:  recursive query "t" does not have the form non-recursive-term UNION [ALL] recursive-term

Will look closer later.  Thanks for the report.

            regards, tom lane



В списке pgsql-bugs по дате отправления: