Skip to content

Instantly share code, notes, and snippets.

@chanmix51
Last active September 4, 2015 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chanmix51/331987 to your computer and use it in GitHub Desktop.
Save chanmix51/331987 to your computer and use it in GitHub Desktop.
transliteration in plpgsql
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, 'áàâäåáăąãāçċćčĉéèėëêēĕîïìíīñôöøõōùúüûūýÿỳ', 'aaaaaaaaaaccccceeeeeeeiiiiinooooouuuuuyyy');
text_out := translate(text_out, 'ÁÀÂÄÅÁĂĄÃĀÇĊĆČĈÉÈĖËÊĒĔÎÏÌÍĪÑÔÖØÕŌÙÚÜÛŪÝŸỲ', 'AAAAAAAAAACCCCCEEEEEEEIIIIINOOOOOUUUUUYYY');
text_out := replace(text_out, 'æ', 'ae');
text_out := replace(text_out, 'Œ', 'OE');
text_out := replace(text_out, 'Æ', 'AE');
text_out := replace(text_out, 'ß', 'ss');
text_out := replace(text_out, 'œ', 'oe');
RETURN text_out;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment