
DECLARE
_setting luticate_settings;
_setting_user luticate_settings_users;
BEGIN
    SELECT * INTO _setting FROM luticate_settings WHERE "name" = _setting_name AND NOT "is_admin";
    IF _setting IS NULL THEN
        setting := NULL;
    ELSE
        IF NOT _setting.is_blocked THEN
            SELECT * INTO _setting_user FROM luticate_settings_users WHERE "user_id" = _user_id AND "name" = _setting_name;
            IF _setting_user IS NOT NULL THEN
                _setting.value := _setting_user.value;
            END IF;
        END IF;
        setting := to_json(_setting);
    END IF;
END;
