Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Mikulas / gist:a5b95be4e4858c63b332
Last active December 3, 2018 11:15
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ň!');