Thread: pgsql: Fix bug with WITH RECURSIVE immediately inside WITH RECURSIVE.

pgsql: Fix bug with WITH RECURSIVE immediately inside WITH RECURSIVE.

From
tgl@postgresql.org (Tom Lane)
Date:
Log Message:
-----------
Fix bug with WITH RECURSIVE immediately inside WITH RECURSIVE.  99% of the
code was already okay with this, but the hack that obtained the output
column types of a recursive union in advance of doing real parse analysis
of the recursive union forgot to handle the case where there was an inner
WITH clause available to the non-recursive term.  Best fix seems to be to
refactor so that we don't need the "throwaway" parse analysis step at all.
Instead, teach the transformSetOperationStmt code to set up the CTE's output
column information after it's processed the non-recursive term normally.
Per report from David Fetter.

Tags:
----
REL8_4_STABLE

Modified Files:
--------------
    pgsql/src/backend/parser:
        analyze.c (r1.389.2.1 -> r1.389.2.2)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/analyze.c?r1=1.389.2.1&r2=1.389.2.2)
        parse_clause.c (r1.189.2.1 -> r1.189.2.2)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_clause.c?r1=1.189.2.1&r2=1.189.2.2)
        parse_cte.c (r2.6 -> r2.6.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_cte.c?r1=2.6&r2=2.6.2.1)
        parse_expr.c (r1.241 -> r1.241.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_expr.c?r1=1.241&r2=1.241.2.1)
    pgsql/src/include/parser:
        analyze.h (r1.40 -> r1.40.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/analyze.h?r1=1.40&r2=1.40.2.1)
        parse_cte.h (r1.2 -> r1.2.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/parse_cte.h?r1=1.2&r2=1.2.2.1)
        parse_node.h (r1.62 -> r1.62.2.1)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/parse_node.h?r1=1.62&r2=1.62.2.1)
    pgsql/src/test/regress/expected:
        with.out (r1.10.2.1 -> r1.10.2.2)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/with.out?r1=1.10.2.1&r2=1.10.2.2)
    pgsql/src/test/regress/sql:
        with.sql (r1.9.2.1 -> r1.9.2.2)
        (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/with.sql?r1=1.9.2.1&r2=1.9.2.2)