title: NULL handling in a least() function in Postgres/SQL
body: <p>I want the query to return the least of the two columns. However if both col1 and col2 are NULL, then return NULL. I've tried coalesce() and nvl() but both don't handle the case when both col1 and col2 are NULL.</p>
  
  <p>For col1 = 3 and col = 2: </p>
  
  <pre><code>select least(coalesce(3, 1000000), coalesce(2, 1000000))
  </code></pre>
  
  <p>This works, output is 2. </p>
  
  <p>This also works for col1 = 3 and col2 = NULL: </p>
  
  <pre><code>select least(coalesce(3, 1000000), coalesce(NULL, 1000000))
  </code></pre>
  
  <p>However, this does not work when col1 = NULL and col2 = NULL</p>
  
  <pre><code>select least(coalesce(null, 1000000), coalesce(null, 1000000))
  </code></pre>
  
  <p>This gives me 1000000 instead of null. 
  How can I account for this scenario? </p>