Nice stuff.
Is it possible to avoid the special case for 0 columns by using theUNION ALL syntax I showed?
-- Álvaro Herrera https://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services