(WITH cte1 AS ((SELECT * FROM demo))
(SELECT *
FROM base
INNER JOIN cte1
ON true)
union
WITH cte2 AS ((SELECT * FROM example))
(SELECT *
FROM level
LEFT JOIN cte2
ON true))
which fails.
with this PR it produces:
(( WITH cte1 AS ((SELECT * FROM demo))
(SELECT *
FROM base
INNER JOIN cte1
ON true) )
union
( WITH cte2 AS ((SELECT * FROM example))
(SELECT *
FROM level
LEFT JOIN cte2
ON true) ))
When doing a union over queries that use a with clause the with clauses aren't inside parens when they need to be for valid syntax.
e.g.
without this PR produces:
which fails.
with this PR it produces: