PostgreSQL nested CTE and UNION

The mystery is solved: the behavior I was observing is a known bug. I sent the same original post to a PostgreSQL-specific list and got this answer:

This is a bug :-(. The parse analysis code seems to think that WITH
can only be attached to the top level or a leaf-level SELECT within a
set operation tree; but the grammar follows the SQL standard which
says no such thing. The WITH gets accepted, and attached to the
intermediate-level UNION which is where syntactically it should go,
and then it’s entirely ignored during parse analysis. Will see about
fixing it.

      regards, tom lane

http://archives.postgresql.org/pgsql-novice/2012-07/msg00113.php

Leave a Comment