DROP FUNCTION IF EXISTS ies.t_medical_act_delete CASCADE;
CREATE  FUNCTION ies.t_medical_act_delete()
RETURNS TRIGGER AS $$
BEGIN
    -- Проверяем, если FED_DATE не пустое
    IF OLD.fed_date IS NOT NULL THEN
        RAISE EXCEPTION 'Нельзя удалять запись, если FED_DATE не пустое';
    END IF;

    -- Если FED_DATE пустое, просто разрешаем удаление. 
    RETURN OLD;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS t_medical_act_before_delete ON ies.t_medical_act;
CREATE TRIGGER t_medical_act_before_delete
BEFORE DELETE ON ies.t_medical_act
FOR EACH ROW EXECUTE FUNCTION ies.t_medical_act_delete();