title: Pipe regex in SQL before a DISTINCT query
body: <pre><code>--col1 col2 col3 col4          col5
  --A    2.2  red  weapiuheraiub weap
  --D    3.1  blue uifhsuiaewfuh uifh
  --...  ...  ...  ...
  </code></pre>
  
  <p>I need a SQL regular expression that generates <code>col5</code> above based off first four characters of <code>col4</code> above. Something along the lines <code>^(.{4}).*</code> replace with <code>\1</code>. Then I need to pipe it to this "DISTINCT" query shown below:</p>
  
  <pre><code>SELECT t.* 
  FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY col5 ORDER BY col5) AS SEQNUM 
  FROM table_name t
  ) t 
  WHERE SEQNUM = 1;
  </code></pre>
  
  <p>This "DISTINCT" query keeps only one unique occurrence (the first) of each value for <code>col5</code> and filters out the rest. It also preserves all columns in my table.</p>
  
  <p>How do I do create such a pipe in SQL (my desired regex --> to my "DISTINCT" function)? Or do I have to nest? And how would I do that?</p>