I have a column with phone numbers that are in string format due to the fact that there might be special characters in the middle. I already cleaned it up, and now I would like to add "55" to the beginning of the string in case there isn't already.
My query:
SELECT leads.name as "lead's name",
NULLIF(regexp_replace(leads.phone, '\D','','g'), '') as "lead's phone"
FROM leads
ORDER BY leads.created_at DESC
Observation 1: It is indifferent to me whether the result is in number format or string format.
Observation 2: It is a query on Metabase. I believe to be the most recent version of PostgreSQL.
Observation 3: I found a similar question that helps adding the "55" to the beginning of the string, but there is no check to see whether there already is a "55" in the beginning of the string. How to add string at the beginning of a string, if it is missing or wrong
Thanks!!