I wrote:
> The first solution that comes to mind is to pay attention to the
> interdependencies of the CTEs, and perform the cleanup in an appropriate
> order (here, the ModifyTable for y needs to be cycled first).
Doh ... actually, we already *are* ordering the CTEs in dependency
order, so it's a one-liner fix to do the shutdowns in reverse order.
regards, tom lane