create or replace function convert_to_initials(
    p_name varchar,
    p_surname varchar,
    p_patronymic varchar
) returns varchar as $$
begin
    if p_patronymic is null or p_patronymic = '' then
        return concat(substring(p_name from 1 for 1), '. ', p_surname);
    end if;

    return concat(substring(p_patronymic from 1 for 1), '. ', substring(p_name from 1 for 1), '. ', p_surname);
end;
$$ language plpgsql;