Skip to content

Instantly share code, notes, and snippets.

@buildbreakdo
buildbreakdo / gist:3f3bde7cb86f68f975bab92561c7158b
Created October 12, 2017 19:20 — forked from Mikulas/gist:a5b95be4e4858c63b332
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ň!');