I wrote: > After a bit of further fooling, I found that we could make that > work with LEFT JOIN LATERAL. This formulation has a different > problem, which is that if you do want most or all of the output, > computing each sub-aggregation separately is probably less > efficient than it could be. But this is probably the better way > to go unless someone has an even better idea.
Hearing no better ideas, pushed. regards, tom lane