We use JIRA and Confluence. If you know those products, the rest of this will make (hopefully) sense.
We use a confluence macro to execute arbitrary SQL queries against our JIRA instance. There is a 'sql' plugin that lets us do this. And it's the nature of the plugin that it can handle multiple resultsets in a way that is pleasingly laid out (it generates HTML we like).
In other words, the way it handled multiple single-row, multi-column tables is exactly what we wanted, HTML-formatting wise.
Now that I'm using postgres, the plugin handles a single multi-row, multi-column table quite differently.
So, because the ouput is being manhandled by the plugin, I need the output to match what the plugin is expecting.
I've kludged something up. There's a way to get the output of the plugin to be recursively evaluated. So now what I do is write one plugin call, which calls my 'outer' PG function. This first function generates one row each, for each 'table/resultset' I was generating in the sybase version. And in these rows I concatenate text to form a second plugin call, which is then evaluated by Confluence, and the second plugin call invokes an 'inner' PG function, which generates my single-row, multi-column table.
so yes, it's "n+1" calls to postgresql.