I have following table in postgres
col1
A018
B672
I would like to add a dot first two character. The expected output is:
col1 col2
A018 A01.8
B672 B67.2
I have tried below query so far
with missed_codes as (
SELECT col1, regexp_replace(col1, '(.{2})(?!$)', '1.') as col2 FROM table
)
select * from missed_codes ;
I am getting this output
col1 col2
A018 1.18
B672 1.72
Any help is highly appreciated!
2
Answers
For your sample data, you don’t need regex, just
left
andsubstr
:Output:
Demo on dbfiddle.uk
If I understand correctly you need to add a dot after first two digits, In this case you need to use
regexp_replace
:Demo here