Skip to content

Instantly share code, notes, and snippets.

@lechup
Forked from thomasbilk/slugify.sql
Last active November 11, 2018 16:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lechup/a69d1ee6116a39a7b12ca85efd5febf7 to your computer and use it in GitHub Desktop.
Save lechup/a69d1ee6116a39a7b12ca85efd5febf7 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 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