DROP FUNCTION IF EXISTS ies.t_insured_policy_insert_update_fio CASCADE;
CREATE  FUNCTION ies.t_insured_policy_insert_update_fio()
RETURNS TRIGGER AS $$
BEGIN
		new.FIO = replace(new.LastName || CHR(160) || new.FirstName || coalesce(CHR(160) || new.Patronymic, CHR(160)),'ё','е');

    RETURN NEW;
END;
$$ LANGUAGE plpgsql;


DROP TRIGGER IF EXISTS t_insured_policy_before_insert_update_fio ON ies.t_insured_policy;
CREATE TRIGGER t_insured_policy_before_insert_update_fio
BEFORE INSERT OR UPDATE ON ies.t_insured_policy
FOR EACH ROW EXECUTE FUNCTION ies.t_insured_policy_insert_update_fio();