1

HI I have one doubt in snow flake server. how to handle non ascii value in snowflake

table : emp 

Empno|Empname
1    |ravÉi
2    |banu raju
3    |raḠu kumar

based on above data i want output like below

Empno|Empname
1    |ravEi
2    |banu raju
3    |raGu kumar

I have tried like below

select empno,uncode(empname,ecoding='utf-8')lname from emp

but above query throwing error: sql compilation erro: error line 1 at postition 27 invalid identifier encoding

can you please tell me how to write query to achive this task in snow flake server .

  • Does this answer your question? [Removing accents from string in Snowflake](https://stackoverflow.com/questions/66606576/removing-accents-from-string-in-snowflake) – Felipe Hoffa Feb 01 '23 at 02:35

2 Answers2

0

did you try, it should work , the function Unicode returns the Unicode code point for the first Unicode character in a string.

select empno,empname from emp; 

select unicode('ravÉi')lname from dual;  will return the value

enter image description here

Himanshu Kandpal
  • 1,261
  • 8
  • 11
0

Given your sample input and output what you really want is to replace Unicode characters with their closest ASCII equivalent.

A JS UDF in Snowflake can help you do that:

You can solve this with a JS UDF in Snowflake:

CREATE OR REPLACE FUNCTION normalize_js(S string)
  RETURNS string
  LANGUAGE JAVASCRIPT
  AS 'return S.normalize("NFD").replace(/\p{Diacritic}/gu, "")'
;

select normalize_js('áéÉña');

-- 'aeEna'

See https://stackoverflow.com/a/66606937/132438.

Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325