-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathslugify_ru.sql
More file actions
27 lines (27 loc) · 772 Bytes
/
slugify_ru.sql
File metadata and controls
27 lines (27 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
create or replace function public.slugify_ru(str text)
returns text
language plpgsql
set search_path = ''
as $$
declare
_out text;
begin
_out := translate(
lower(str),
'абвгдеёзийклмнопрстуфыэ',
'abvgdeeziyklmnoprstufye'
);
_out := replace(_out, 'ж', 'zh');
_out := replace(_out, 'х', 'kh');
_out := replace(_out, 'ц', 'ts');
_out := replace(_out, 'ч', 'ch');
_out := replace(_out, 'ш', 'sh');
_out := replace(_out, 'щ', 'sch');
_out := replace(_out, 'ь', '');
_out := replace(_out, 'ъ', '');
_out := replace(_out, 'ю', 'yu');
_out := replace(_out, 'я', 'ya');
_out := regexp_replace(_out, '[^a-z0-9]+', '-', 'g');
return trim(_out, '-');
end
$$;