I have been thinking for a while about this optimization. The thing is, there is currently no way of forcing this CTE evaluation other than referencing it from other query parts. I think this is little clumsy. What if we use MATERIALIZE here for this purpose? So,
I find myself usually, if something has side-effects, returning result information about what effects it had. That means propagating the result (usually a jsonb object) out of the main query so the caller (usually a function) can grab ahold of it to return to the client. Even just a row count and a label works.