Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION public.url_slug (
- s_texto text
- )
- RETURNS varchar AS
- $body$
- DECLARE
- total integer;
- BEGIN
- s_texto := replace(s_texto , 'U$', 'dolares');
- s_texto := replace(s_texto , 'R$', 'reais');
- s_texto := regexp_replace(translate(replace(lower(s_texto), ' ', '-'),
- 'áàâãäåāăąÁÂÃÄÅĀĂĄèééêëēĕėęěĒĔĖÉĘĚìíîïìĩīĭÌÍÎÏÌĨĪĬóôõöōŏőÒÓÔÕÖŌŎŐùúûüũūŭůÙÚÛÜŨŪŬŮçÇÿ&,.ñÑ',
- 'aaaaaaaaaaaaaaaaaeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuuccy_--nn'), E'[^\\w -]', '', 'g');
- SELECT COUNT(not_slug) INTO total FROM noticias WHERE not_slug = s_texto;
- IF total > 0 THEN
- RETURN s_texto || '-' || total+1;
- ELSE
- RETURN s_texto;
- END IF;
- END;
- $body$
- LANGUAGE 'plpgsql'
- VOLATILE
- CALLED ON NULL INPUT
- SECURITY DEFINER
- COST 100;
Add Comment
Please, Sign In to add comment