title: Min per row in Presto
body: <p>I have a table with 4 columns of type <code>timestamp tz</code> in PrestoDB - no NULL values - and am unable to get the min value per row.  It seems counter intuitive because:</p>
  
  <pre><code>SELECT
  (SELECT MIN(Col) FROM (VALUES (1), (2), (3), (4)) AS X(Col)) AS TheMin
  FROM mytable
  </code></pre>
  
  <p>^ using fake integer will return 1 for all rows </p>
  
  <p>Yet in my table:</p>
  
  <p><a href="https://i.stack.imgur.com/JUd0O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JUd0O.png" alt="enter image description here"></a></p>
  
  <pre><code>SELECT
  (SELECT MIN(Col) FROM (VALUES (_col2), (_col3), (_col4), (_col5)) AS X(Col)) AS TheMin
  FROM mytable
  </code></pre>
  
  <p>returns <code>Presto query has failed. type cannot be null</code>  </p>
  
  <p>How is this possible when the data types in the columns are all <code>timestamp tz</code> and there are zero NULL values ? </p>
  
  <p>What is the workaround here for finding the min timestamp per row using the columns as <code>VALUES</code> ? </p>