forked from rin-nas/postgresql-patterns-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslugify.sql
More file actions
26 lines (26 loc) · 737 Bytes
/
slugify.sql
File metadata and controls
26 lines (26 loc) · 737 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
create or replace function slugify(str text)
returns text
language plpgsql
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
$$;