1- create or replace function email_parse (
1+ create or replace function public . email_parse(
22 email text ,
33 username out text ,
44 domain out text
@@ -11,11 +11,12 @@ create or replace function email_parse(
1111 parallel safe
1212 language sql
1313 set search_path = ' '
14+ cost 5
1415as
1516$$
1617 -- https://en.wikipedia.org/wiki/Email_address
1718 select t[1 ] as username, t[2 ] as domain
18- from regexp_match(email, ' ^(.+)@([^@]+)$' , ' ' ) as t
19+ from regexp_match(email, ' ^(.+)@([^@\s ]+)$' , ' ' ) as t
1920 where octet_length(email) between 6 and 320
2021 and position(' @' in email) > 1 -- speed improves
2122 and octet_length(t[1 ]) <= 64 and octet_length(t[2 ]) <= 255 ;
2627 begin
2728 -- positive
2829 assert (select username = ' 111@222' and domain = ' ya.ru'
29- from email_parse(' 111@222@ya.ru' ) as t);
30+ from public . email_parse (' 111@222@ya.ru' ) as t);
3031 -- negative
31- assert email_parse(' 123@' ) is null ;
32- assert email_parse(' @123' ) is null ;
32+ assert public .email_parse (' 123@' ) is null ;
33+ assert public .email_parse (' @123' ) is null ;
34+ assert public .email_parse (' do@it. com' ) is null ;
3335 end;
3436$$;
0 commit comments