-
-
Save heysamtexas/2348365 to your computer and use it in GitHub Desktop.
transliteration in plpgsql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION transliterate(my_text VARCHAR) RETURNS varchar AS $$ | |
DECLARE | |
text_out VARCHAR DEFAULT ''; | |
BEGIN | |
text_out := my_text; | |
text_out := translate(text_out, 'àâäåáăąãā', 'aaaaaaaaa'); | |
text_out := replace(text_out, 'æ', 'ae'); | |
text_out := translate(text_out, 'çċćčĉ', 'ccccc'); | |
text_out := translate(text_out, 'éèėëêēĕ', 'eeeeeee'); | |
text_out := translate(text_out, 'îïìíī', 'iiiii'); | |
text_out := translate(text_out, 'ñ', 'n'); | |
text_out := translate(text_out, 'ôöøõō', 'ooooo'); | |
text_out := replace(text_out, 'œ', 'oe'); | |
text_out := translate(text_out, 'ùúüûū', 'uuuuu'); | |
text_out := translate(text_out, 'ýÿỳ', 'yyy'); | |
text_out := replace(text_out, 'ß', 'ss'); | |
text_out := translate(text_out, 'ÀÂÄÅÁĂĄÃĀ', 'AAAAAAAAA'); | |
text_out := replace(text_out, 'Æ', 'AE'); | |
text_out := translate(text_out, 'ÇĊĆČĈ', 'CCCCC'); | |
text_out := translate(text_out, 'ÉÈĖËÊĒĔ', 'EEEEEEE'); | |
text_out := translate(text_out, 'ÎÏÌÍĪ', 'IIIII'); | |
text_out := translate(text_out, 'Ñ', 'N'); | |
text_out := translate(text_out, 'ÔÖØÕŌ', 'OOOOO'); | |
text_out := replace(text_out, 'Œ', 'OE'); | |
text_out := translate(text_out, 'ÙÚÜÛŪ', 'UUUUU'); | |
text_out := translate(text_out, 'ÝŸỲ', 'YYY'); | |
RETURN text_out; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment