How about keeping track of the oldest create_date and adding a WHERE clause to the query that returns the asset.copy data, but only use this WHERE clause when you have the limit + offset number of records in v_result.
So, once you have a possible full set to return, only look for newer items after that?
IF (SELECT count(skeys(v_results)) == p_limit + p_offset)
SELECT c.call_number, c.create_date, c.status, c.location
FROM asset.copy c
WHERE c.circ_lib = v_circ_lib AND NOT c.deleted'
AND c.create_date > oldest_created_date_in_v_results
ORDER BY c.create_date DESC;
ELSE
SELECT c.call_number, c.create_date, c.status, c.location
FROM asset.copy c
WHERE c.circ_lib = v_circ_lib AND NOT c.deleted'
ORDER BY c.create_date DESC;
END IF;
I do not know if SELECT count(skeys(v_results)) is valid syntax, but getting a count of the keys should be do able.
And doing it here means it is only done once per lib, so not too expensive.
How about keeping track of the oldest create_date and adding a WHERE clause to the query that returns the asset.copy data, but only use this WHERE clause when you have the limit + offset number of records in v_result.
So, once you have a possible full set to return, only look for newer items after that?
IF (SELECT count(skeys( v_results) ) == p_limit + p_offset) created_ date_in_ v_results
SELECT c.call_number, c.create_date, c.status, c.location
FROM asset.copy c
WHERE c.circ_lib = v_circ_lib AND NOT c.deleted'
AND c.create_date > oldest_
ORDER BY c.create_date DESC;
ELSE
SELECT c.call_number, c.create_date, c.status, c.location
FROM asset.copy c
WHERE c.circ_lib = v_circ_lib AND NOT c.deleted'
ORDER BY c.create_date DESC;
END IF;
I do not know if SELECT count(skeys( v_results) ) is valid syntax, but getting a count of the keys should be do able.
And doing it here means it is only done once per lib, so not too expensive.