I am trying to replace a pattern in a Redshift table using regular expression. I have been trying with REGEXP_RELACE
but no success so far.
My data, with columns name sequence
and varchar data type, looks like:
1420311 > 1380566 > 1380566 > 9991380564
1489773 > 9991489773
1367309 > 1367309 > 9991367309
I would like to use REGEXP_RELACE
(or any other function) in SQL Redshift to get the following result:
1420311 > 1380566 > 1380566 > 1380564 > 999
1489773 > 1489773 > 999
1367309 > 1367309 > 1367309 > 999
So that is finding the 999 sequence when it appears at the start of the string, and putting it last preceded by a >
and maintain the remaining string.
Greatly appreciate any help!
If you just want a query which can generate this output then the following should work: