Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buildbreakdo/3f3bde7cb86f68f975bab92561c7158b to your computer and use it in GitHub Desktop.
Save buildbreakdo/3f3bde7cb86f68f975bab92561c7158b to your computer and use it in GitHub Desktop.
PostgreSQL UTF-8 to ASCII folding and webalize
CREATE EXTENSION unaccent;
CREATE OR REPLACE FUNCTION webalize(varchar) RETURNS text AS $$
SELECT trim(both '-' from regexp_replace(lower(unaccent($1)), '[^a-z0-9]+', '-', 'g'));
$$ LANGUAGE SQL;
SELECT unaccent('Příliš žlutý kůň 91. stupeň!');
-- Prilis zluty kun 91. stupen!
SELECT webalize('Příliš žlutý kůň 91. stupeň!');
-- prilis-zluty-kun-91-stupen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment