geek2000 geek2000 - 2 months ago 8
SQL Question

Add a string to a specific location in Postgres

I need to add a dot in the 4th position of each string in a column. How can I perform this in Postgres?

Example:

'1234'
should become
'123.4'

Answer

For example use left / right:

db=> select left('1234', 3) || '.' || right('1234', -3);
 ?column? 
----------
 123.4