Last active
December 3, 2018 11:15
-
-
Save Mikulas/a5b95be4e4858c63b332 to your computer and use it in GitHub Desktop.
PostgreSQL UTF-8 to ASCII folding and webalize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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