title: Postgres. Concatenate fields without fixed length
body: <p>I have two columns (A and B) on table 1, and I want to concatenate them into another column (C) only if the beginning of B is not A, and if that is not the case, just copy B into C.
  The key point here is that A and B do not have a fixed length, so I don't think I can use left(), since it needs a specific length.
  For example: </p>
  
  <pre><code>ID        A                            B 
  1          5                          48721
  2         98                          98555
  3         98                            136
  4        841                     8417740313
  5        841                         133889
  </code></pre>
  
  <p>In this case, column C should include: </p>
  
  <ol>
  <li>For ID=1: 548721</li>
  <li>For ID=2: 98555</li>
  <li>For ID=3: 98136</li>
  <li>For ID=4: 8417740313 </li>
  <li>For ID=5: 841133889</li>
  </ol>
  
  <p>I was trying: </p>
  
  <pre><code>UPDATE 1
  SET C = B
  WHERE LEFT (B) = A
  UPDATE 1
  SET C = concat(A,B)
  WHERE LEFT(B) &lt;&gt; A
  </code></pre>
  
  <p>But it doesn't work, since I need to give left() a fixed length. What would you guys do?</p>