title: Redshift - Weird behaviour from TO_TIMESTAMP function
body: <p>I'm trying to create a timestamp from separated date and time fields. The date field is of 'date' type while the time field is 'varchar'. The table has just over 60k records. Date is in YYYY-MM-DD format, ie 2017-07-25. Time is in HH:MIpm format, ie 4:25pm.</p>
  
  <p>I run the following query to try and create the timestamp:</p>
  
  <pre><code>select *, 
         to_timestamp(TO_CHAR("date", 'YYYY-MM-DD')||' '||(case when "time"='' then '11:59pm' else "time" end), 'YYYY-MM-DD HH:MIpm') as REQUIRED_TIMESTAMP 
  from TABLE;
  </code></pre>
  
  <p>However, it only returns 1023 records. Here's what makes things even weirder:</p>
  
  <p>i. The records that are returned aren't always the same on subsequent runs. However, there is always 1023 records returned. On one run the first few IDs would be 43, 55, 63, 69, etc. and on the next run it'd be different. Sometimes I'd get the following error:</p>
  
  <p><code>Query 1 ERROR: ERROR:  invalid value for "HH" in source string</code></p>
  
  <p>ii. I used <code>CAST(as timestamp)</code> instead, it'd show the timestamp in a different format but again it'd only show 1023 records.</p>
  
  <p>iii. It's not a specific time value that is omitted. A record with time 7:30pm may be omitted, but another record with 7:30pm shows up just fine.</p>
  
  <p>Is there something wrong with my query? Could it be a problem with the data or is this an issue with Redshift?</p>