Skip to content

Instantly share code, notes, and snippets.

@thomasbilk
Last active June 10, 2018 00:33
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 thomasbilk/6112454 to your computer and use it in GitHub Desktop.
Save thomasbilk/6112454 to your computer and use it in GitHub Desktop.
Pseudo Transliteration for Postgres aka `slugify`
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;
@lechup
Copy link

lechup commented Mar 8, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment