Search code examples
clickhouse

How replace each accented characters with non-accented characters foreach word in array in clickhouse?


I have a array of words, ['camión', 'elástico', 'Árbol'] and I want replace accented characters with non-accented characters for each word in array (['camion', 'elastico', 'Arbol'])

I'm searching some as this

SELECT arrayMap(x -> replaceRegexpAll(x, ['á', 'é', 'í', 'ó', 'ú'], ['a', 'e', 'i', 'o', 'u']), ['camión', 'elástico', 'Árbol']) AS word

And I want this result:

['camion', 'elastico', 'arbol']

Replacing each characters accents to withouth accent, but this doesn't work...

Any idea from solve?

Thanks


Solution

  • New feature add functions translate(string, from_string, to_string) and translateUTF8(string, from_string, to_string).

    These functions replace characters in the original string according to the mapping of each character in from_string to to_string.

    SELECT  arrayMap(y ->  translateUTF8(y,'áéíóúÁÉÍÓÚ','aeiouAEIOU'), ['camión', 'elástico', 'Árbol']) r
    
    r                            |
    -----------------------------+
    ['camion','elastico','Arbol']|