I am using postgresql as database system (v 9.6.5). I have a table T with a column code. I want to add a new column sorting_code. sorting_code is an another way to write the code.
code is a combination of (in this order) characters, numbers and +, e.g 12e+, 234rr++ or 9999mo are examples of codes. In regex, my code is something like:
[0-9]+[a-z]*\+*
(only numbers are required)
What I want to do for my column sorting_code is to transform my code like that:
12e+ => 000120000e0000+
234rr++ => 00234000rr000++
9999mo => 09999000mo00000
In other words, each part (characters, numbers and +) must be exactly 5 characters long. Missing characters being replaced by 0.
I have already a lot of rows in my table T with code. What could be my psql request to create my new column sorting_code?
Thank you