I think the incrementing of the v_found counter should be wrapped in a check to see if the key has been defined before.
IF NOT v_results ? v_record::TEXT THEN
v_found := v_found + 1;
END IF;
In the case where a record that has already been added to v_results has a copy from a different circ lib that has a newer date than the current copy's date stored in v_results, then the current v_found will be incremented twice for the same record.
I think the incrementing of the v_found counter should be wrapped in a check to see if the key has been defined before.
IF NOT v_results ? v_record::TEXT THEN
v_found := v_found + 1;
END IF;
In the case where a record that has already been added to v_results has a copy from a different circ lib that has a newer date than the current copy's date stored in v_results, then the current v_found will be incremented twice for the same record.