-
-
Save lechup/a69d1ee6116a39a7b12ca85efd5febf7 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 regexp_replace( | |
lower(translate(str, | |
'äëïöüáéíóúâêîûôåãõàèìòùřšěčůńýśćłęążźĄŃÝŚĆŁĘÄËÏÖÜÁÉÍÓÚÂÊÎÛÔÅÃÕÀÈÌÒÙŘŠĚČŮŻŹß ²ø®', | |
'aeiouaeiouaeiouaaoaeioursecunyscleazzANYSCLEAEIOUAEIOUAEIOUAAOAEIOURSECUZzs-2dR' | |
-- missing chars will be removed | |
)), | |
-- strip all others chars than [^a-z0-9 \-] | |
'[^a-z0-9 \-]', | |
'', | |
'g' | |
); | |
END | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment