system.tag.queryTagHistory() not returning t_stamp column

I'm scripting a tag history query and want a wide table with AsStored values. I'm expecting a t_stamp column but not getting it. (I am getting a column for each tag defined in the paths list.)

    # Read records for the last two hours.
    startD = system.date.addHours(system.date.now(), -2)
    endD = system.date.addMinutes(system.date.now(), -15)
    
    # Query the historian.
    ds = system.tag.queryTagHistory(
        paths, 
        startDate = startD, 
        endDate = endD, 
        returnFormat = 'Wide', 
        columnNames = colNames, 
        ignoreBadQuality = True, 
    )
	headers = system.dataset.getColumnHeaders(ds)
	for h in headers:
		print h

Can anyone spot my error? Am I missing a parameter?

What's colNames defined as/what result do you get if you omit that parameter?

You do know that you get repeated data when you combine these? It’s a “best effort” format that simply cannot be “good”.

Consider using tall format and then use my groupBy() to obtain the per-tag timestamp/value combinations.

Thanks, Paul.

  • Omitting columnNames = colNames returns the t_stamp column.
  • Adding t_stamp to the colNames list also solves the problem.

I'll investigate further.

You do know that you get repeated data when you combine these?

Thanks, Phil. Yes, I am aware of that. Your toolkit is installed on this gateway so I can try the groupBy() function.

I bet columnNames just has to be len(tagPaths) + 1 in size with Wide return format.

This sounds familiar, actually... like maybe there is/was a bug in this area a long time ago.

1 Like

Phil, I'm generating the wide table in a gateway scheduled event. I don't think I can use the groupBy() function is this case. Isn't it expression language only?

Correct. You’d have to script the equivalent. (Highly recommended.)