Last active
June 10, 2018 00:33
-
-
Save thomasbilk/6112454 to your computer and use it in GitHub Desktop.
Pseudo Transliteration for Postgres aka `slugify`
This file contains 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 slugify(str text) RETURNS text AS $$ | |
BEGIN | |
RETURN lower(translate(str, | |
'äëïöüáéíóúâêîûôåãõàèìòùřšěčůńýśćłęąĄŃÝŚĆŁĘÄËÏÖÜÁÉÍÓÚÂÊÎÛÔÅÃÕÀÈÌÒÙŘŠĚČŮß :;-²ø®(),./\"’`''', | |
'aeiouaeiouaeiouaaoaeioursecunyscleaANYSCLEAEIOUAEIOUAEIOUAAOAEIOURSECUs____2dR' -- missing chars will be removed | |
)); | |
END | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing, I've updated Your gist by adding
regexp_replace
that strips all other chars than [0-9A-Za-z -]. You can see it here:https://gist.github.com/lechup/a69d1ee6116a39a7b12ca85efd5febf7