Quering Tag History Return One record after the endData

Hi, I'm trying to fetch data by perspective tag history binding. Although I set "As Stored" Query Mode with fixed begin date and end date the results set always returns the next record after the end date.
Here are the settings:

This is the result:
historian-query-binding-results

And this is the raw data in the database (in reverse time order):

I played with system.tag.queryTagHistory with the following parameters:
ds = system.tag.queryTagHistory(
paths = paths,
startDate = value.begin,
endDate = value.end,
aggregationMode = "LastValue",
ignoreBadQuality = True ,
returnFormat = "Tall",
includeBoundingValues = False,
returnSize = -1,
noInterpolation = True,
)
But this give the same results.

I'm wondering if Ignition returns this additional records by design or I miss something. I just need to fetch the records with timestamps later than beginDate and earlier than endData.

By design, IIRC. Ignition is trying to satisfy your complete datetime span. This may be affected by the deadband mode--Analog mode is more complicated and may require this.

Thanks for the fast reply Phil. The dead band is set to Discrete.
I'll use the queryTagHistory() function and then remove the last record. But it still seems strange to me - this additional record should be optional (when includeBoundingValues is set). Otherwise, If I request the records from 10:00:00 to 10:59:59 o'clock I'll also get the next record which might be at 11:05:03 or a day after. It means that I can't show the raw records for a given time period in a table without coding.

1 Like

Hello,

I had similar problem and got IA support involved. Below is outcome of that support case, maybe someone will benefit from this.

Check sqlth_te table for tag in question. It should have value of "0" in querymode column of that table for "Discrete" Deadband Style.

E.g. on attached screenshot querymode is "3", which corresponds to "Analog" Deadband Style. This is despite "Discrete" Deadband Style shown in tag properties (which looks like a bug). Another situation when it can happen is if tag got Deadband Style changed from "Analog" to "Discrete" and you query timespan reaches "Analog" Deadband Style period.

In my case I updated manually querymode to "0" for tags causing me trouble. If you have system running in production then you would need to consider risk involved, backups etc.

1 Like