Guest User

Untitled

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