I wrote:
> Surely that breaks things entirely (if it doesn't, then we are badly
> under-testing this area). A nil list is just a null pointer, so
> appending to "new_cte_list" later isn't going to affect what was
> previously put into the innerwiths list.
Here's a patch that I think fixes it correctly, including a test
case that doesn't work with your patch.
regards, tom lane