I think my question is the same than this one, but it wasn't clear so the responses are not what I'm looking for.
I have a table built by osm2pgsql of 70 columns and about a million rows. Of the 70 columns, only 2 have values for each row (one is a geolocation with an index on it), the remaining ones form a sparse matrix.
I put in this fiddle a simplified version of what I have and what I want. A little explanation here : each value of each column got its count, and each column also got its count, with a NULL value to indicate that it's the column count.