title: How to generate 12 digit unique number in redshift?
body: <p>I have 3 columns in a table i.e. <code>email_id</code>, <code>rid</code>, <code>final_id</code>.</p>
  
  <p>Rules for <code>rid</code> and <code>final_id</code>:</p>
  
  <ol>
  <li>If the <code>email_id</code> has a corresponding <code>rid</code>, use <code>rid</code> as the <code>final_id</code>.</li>
  <li>If the <code>email_id</code> does not have a corresponding <code>rid</code>(i.e.<code>rid</code> is null), generate a unique 12 digit number and insert into <code>final_id</code> field.</li>
  </ol>
  
  <p>How to generate 12 digit unique number in redshift? </p>