title: How to replace an array of characters in a column of text in PostgreSQL?
body: <p>I have 2 text columns where I need to replace (on update) chars from array 1 ('q','x','y','z') to their index-equivalent value in array 2 ('a','b','c','d').</p>
  
  <p>The closest I've come to atm is to nest the replace calls within each other like so</p>
  
  <pre><code>UPDATE 
      mytable 
  SET 
      col1=replace(
              replace(
                  replace(
                      replace(
                          col1,'q','a'
                      ),'x','b'
                  ),'y','c'
              ),'z','d'
          ),
      col2=replace(
              replace(
                  replace(
                      replace(
                          col2,'q','a'
                      ),'x','b'
                  ),'y','c'
              ),'z','d'
          )        
  </code></pre>
  
  <p>but surely there must be a better way to do this? In my live case I have 14 of those char pairs. If it has any relevance - the chars are a mix of japanese hieroglyphs and accented letters from Swedish alphabet.</p>