Comments on: Make a slug in PostgreSQL translating diacritics http://scottbarnham.com/blog/2010/12/20/make-a-slug-in-postgresql-translating-diacritics/ Code and comments on web development, Django, Python and things (un)related. Wed, 03 Apr 2013 13:15:20 +0000 hourly 1 http://wordpress.org/?v=4.3 By: Mehira http://scottbarnham.com/blog/2010/12/20/make-a-slug-in-postgresql-translating-diacritics/comment-page-1/#comment-990 Mon, 31 Jan 2011 09:11:37 +0000 http://scottbarnham.com/blog/?p=79#comment-990 Very great function.
I used it for creating a postgresql function getslug :

CREATE OR REPLACE FUNCTION getslug(texte varchar) RETURNS VARCHAR AS
$$
DECLARE
    result varchar;
BEGIN
    result := replace(texte , 'æ', 'ae');
    result := replace(result , 'œ', 'oe');
    result := replace(result , '€', 'euros');
    result := replace(result , '$', 'dollars');
    result := replace(result , '£', 'pound');
    result := replace(result , '¥', 'yen');
    result := regexp_replace(translate(replace(lower(result), ' ', '-'), 
        'áàâãäåāăąÁÂÃÄÅĀĂĄèééêëēĕėęěĒĔĖĘĚìíîïìĩīĭÌÍÎÏÌĨĪĬóôõöōŏőÒÓÔÕÖŌŎŐùúûüũūŭůÙÚÛÜŨŪŬŮçÇÿ&,.ñÑ',
        'aaaaaaaaaaaaaaaaaeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuuccy_--nn'), E'[^\\w -]', '', 'g');
    RETURN result;
END;
$$
LANGUAGE PLPGSQL;
]]>