Count not-null columns in row
<p>I'm trying to determine the number of specific columns that are populated, here's what I'm trying to do:</p>

<pre><code>  foo := COALESCE($1.col1, '') || ' ' ||
    COALESCE($1.col2, '') || ' ' ||
    COALESCE($1.col3, '') || ' ' ||
    COALESCE($1.col4, '');
  foo := REPLACE(foo, var, ' ');
  words := string_to_array(foo, ' ');
  RETURN array_length(words, 1);
</code></pre>

<p>where <code>var</code> is white space, <code>\s</code> doesn't seem to work. I'm open to any other methods of finding the number of non-nil columns.</p>