2

I'm trying to replace accented characters from a column to "normal" characters.

select 'áááããã'

I'd like some operation which would return 'aaaaaa'.

2 Answers2

2

Just found a solution with one of my colleagues.

select translate('áááããã','áéíóúãõâêôàç','aeiouaoaeoac')

We can also add a lower() to make it generalized for more cases

select translate(lower('ÁÁÁÃÃÃ'),'áéíóúãõâêôàç','aeiouaoaeoac')
  • Be very sure to test it with different [Collation](https://docs.snowflake.net/manuals/sql-reference/collation.html) as the manual about [translate](https://docs.snowflake.net/manuals/sql-reference/functions/translate.html) mentioned *"Collation Details Arguments with collation specifications are currently not supported. "* – Raymond Nijland Aug 20 '19 at 18:03
2

There is a more general way that uses a built-in JavaScript function to replace them:

Remove Diacritics from string in Snowflake

create or replace function REPLACE_DIACRITICS("str" string)
returns string
language javascript
strict immutable
as
$$
    return str.normalize("NFD").replace(/\p{Diacritic}/gu, "");
$$;

select REPLACE_DIACRITICS('ö, é, č => a, o e, c');
Greg Pavlik
  • 10,089
  • 2
  • 12
  • 29