title: How to COALESCE for empty strings and NULL values?
body: <p>I'm trying to make the fastest COALESCE() that accepts two or more arguments, and returns the first non-null AND non-empty ("") value.</p>
  
  <p>I'm using this:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION coalescenonempty(VARIADIC in_ordered_actual varchar[])
  RETURNS varchar AS $$
    SELECT i
    FROM (SELECT unnest($1) AS i) t
    WHERE i IS NOT NULL AND i &lt;&gt; ''
    LIMIT 1;
  $$ LANGUAGE sql;
  </code></pre>
  
  <p>It's pretty fast, but still nowhere as fast as COALESCE or CASE WHEN statements.</p>
  
  <p>What do you think?</p>