Fix inability to reference CYCLE column from inside its CTE.
authorTom Lane
Fri, 16 Dec 2022 18:07:42 +0000 (13:07 -0500)
committerTom Lane
Fri, 16 Dec 2022 18:07:42 +0000 (13:07 -0500)
commitea5ae4cae6a230e048f0ff4587b54d441712c6fd
treeedb3be9304807bb30055fd2fe29e44d193937030
parent171d7746a21dfb0e19c008b7a398e1ee1ad7f74e
Fix inability to reference CYCLE column from inside its CTE.

Such references failed with "cache lookup failed for type 0"
because we didn't resolve the type of the CYCLE column until after
analyzing the CTE's query.  We can just move that processing
to before the recursive parse_sub_analyze call, though.

While here, invent a couple of local variables to make this
code less egregiously wider-than-80-columns.

Per bug #17723 from Vik Fearing.  Back-patch to v14 where
the CYCLE feature was added.

Discussion: https://postgr.es/m/17723-2c4985ff111e7bba@postgresql.org
src/backend/parser/parse_cte.c
src/test/regress/expected/with.out
src/test/regress/sql/with.sql