title: Getting last word in a string on Amazon Redshift
body: <p>A similar question has already been asked, however Amazon Redshift does not support some of the commands of MySQL, so there is a need to adapt the code.</p>
  
  <p>I am trying to extract the last word out of a string in a given column.</p>
  
  <pre><code>col1 |
  +-----+
  |a    |
  |b c  |
  |d e f|
  </code></pre>
  
  <p>This would be an output:</p>
  
  <pre><code>|result|
  +------+
  |a     |
  |c     |
  |f     |
  </code></pre>
  
  <p>I have tried working with <code>SUBSTRING_INDEX</code>,</p>
  
  <pre><code>SELECT SUBSTRING_INDEX("a b c", " ", -1);
  </code></pre>
  
  <p>however it does not work with Redshift.</p>
  
  <p>Thus, I thought about using <code>SUBSTRING</code> with <code>POSITION</code>, but <code>POSITION</code> finds only the first space and does not seem to work:</p>
  
  <pre><code>SELECT SUBSTRING(column, POSITION (' ' in REVERSE(column)), 10)
  </code></pre>
  
  <p>Any idea how to do this?</p>