-1
Good Afternoon,
I am trying in an output to exchange all digits in the address column for a '!'. I tried the following solution among others, but for some reason I’m not getting what I want.
select project,
commits,
contributors,
replace(address, '[0-9]', '!') as address
from repositories
Output: what I have - 1ECnGua88LpbYq5ta88ZwV8qmnoYj3Mibo --> what I want ! Ecngua!! Lpbyq! ta!! Zwv! qmnoYj! Mibo
Thanks for the help
Which database you are using?
– Tiedt Tech
I’m using the postgresql
– Tooc
SELECT REGEXP_REPLACE(address,'[[:Digit:]]','!','g'); https://www.postgresqltutorial.com/regexp_replace/
– user60252
The best option is certainly the function
regexp_replace
, as answered by Leo. The functionreplace
function character by character:SELECT replace(replace(replace(replace(replace('1ECnGua88LpbYq5ta88ZwV8qmnoYj3Mibo', '1', '!'), '3', '!'), '4', '!'), '5', '!'), '8', '!');
and the functiontranslate
with the corresponding position:SELECT translate('1ECnGua88LpbYq5ta88ZwV8qmnoYj3Mibo', '0123456789', '!!!!!!!!!!');
.– anonimo