Query tag historian data using generic SQL query

I want to query the historian data using (tagName, startTime, endTime) and send the result out as Json file.

I thought abut using named query, but it does not support direct querying the historian tag list.

Then I am thinking about writing query by joining the multiple tag historian data tables to get the result.

Here's the information I found about the tag historian data tables:
https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference

I can try and test out the correct query script for the tag historian, but just wonder whether there's already some premade ignition query I can use straightaway?

The tag history system.tag.* calls are the "premade" query.

Fundamentally, you will be search for the set of tag ids that correspond to your tag path, and the set of partitions that correspond to your time range. Then you will construct a query that unions those partitions together after filtering each for the desired tag and time.

There isn't a single generic query that can do this.

1 Like

Thanks for the reply.

I was testing the following query yesterday.

system.tag.queryTagHistory

It's working if to set the "start time, end time and interval time", but I couldn't figure out how to return only a fixed amount of data points.
For example I want to return only 200 data point, doesn't matter whether it's duration of 1 day or 1 month, for the 200 data point, I can either choose average or last value.

I found the following statement in the doc, but I don't know whether it's the same meaning of "fixed size" as I want.

queryTagHistory literally has a returnSize parameter, documented in the manual page you linked.

1 Like

Thanks.

I have just tested it, when set the returnSize to 10, it will generate 10 results, regardless whether the intervalSeconds settings.