Querying tag history by quantity, not time range (with scripting)

Has anyone successfully used system.tag.QueryTagHistory() to return a fixed number of unmodified values? I want to return the 10 most recent values of a tag whose history I am saving to my db on change.

Just setting the return size on the query function equal to 10 does not accomplish this, instead it divides the time range (in my case I’m not setting the time range, so it’s using the 8 most recent hours) into 10 slices and then does some aggregation/manipulation of the data in each of those time ranges.

Put another way, I want to be able to query tag history like I would use

SELECT TOP(10) t_stamp, myTag FROM myTable ORDER BY t_stamp DESC

But without the headache of doing actual SQL queries on the historian tables.

For reference, this is on a v8 gateway with an MSSQL database.

I would also like to be able to do this. The closest I’ve gotten is:

system.tag.queryTagHistory(paths=pathList, startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="LastValue", returnFormat='Tall')

But this seems to do some interpolation and gives inconsistent results.