[Bug?]: system.tag.queryTagHistory data issue

I'm trying to get a tag's value at 9:00 AM everyday over the past month - say Sept 1st to Oct 1st.

I have two test queries. Query 1 is showing me the values at 9 AM (returnSize = 30) and Query 2 shows me the raw data with aggregationMode = LastValue and returnSize = -1.

I'm noticing the following behavior:

Query 1 Sept 1 Value - doesn't match - Query 2 Sept 1 Value
Query 1 Sept 1 Value - matches - Query 2 Sept 2 Value
Query 1 Sept 2 Value - matches - Query 2 Sept 3 Value
....and so on as shown below

I'm not sure what I'm missing.

Query 1 is shown below.

import time 
from java.text import SimpleDateFormat

endTimestr = "2022-10-01 09:00:00"

inputFormat=SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
startTime = system.date.addMonths(endTime, -1)

path1 = "[Default]AAA/BBB/CCC/Gas Meter Temperature"

dataSet = system.tag.queryTagHistory(paths=[path1], startDate=startTime, endDate=endTime, returnSize=30, 
aggregationMode="LastValue", returnFormat='Wide', noInterpolation=True)
for i in range(dataSet.getRowCount()):
	print dataSet.getValueAt(i,0)
	print dataSet.getValueAt(i,1)

I was able to reproduce your result using power tables, and it really does seem like a bug. When I use system.tag.queryTagHistory with a returnSize parameter of anything other than the default -1, my resultant columns are misaligned by 1 value:

In the above example, the table on the left has a return size of 10, and the table on the right has the default return size.

Query 1 code:
system.tag.queryTagHistory(paths=[path1], startDate=startTime, endDate=endTime, returnSize=10, aggregationMode="LastValue", returnFormat='Wide', noInterpolation=True)

Query 2 code:
system.tag.queryTagHistory(paths=[path1], startDate=startTime, endDate=endTime, returnSize=-1, aggregationMode="LastValue", returnFormat='Wide', noInterpolation=True)

Thanks, I'm a bit confused as well.

Bump. Any help/explanation regarding this behavior please?

Build your own SQL script, query the database manually.
I tried that for weeks.:sweat_smile:
queryTagHistory function does have flaws.

If you want an official answer, you need to contact Support. This forum is not an official support venue.

Ended up doing something similar, thanks.