SELECT `justfunctions.eu.dedup_chars`("Helloooo!")
/*--Output--
Helo!
*/
CREATE OR REPLACE FUNCTION `your_project_id.your_dataset_id.dedup_chars`(`string` string)
RETURNS string AS ((SELECT
STRING_AGG(
IF
(c = SPLIT(string, '')[SAFE_OFFSET(off - 1)],
NULL,
c), '' ORDER BY off)
FROM
UNNEST(SPLIT(string, '')) AS c
WITH OFFSET off)
)
OPTIONS ( description = '''Deduplicates characters in a <string>.''')
SQL User Defined Function (SQL UDF)
See something wrong? Contact us or report an issue on Github.