# Get Tags based on tag attribute

**URL:** <https://forum.inductiveautomation.com/t/get-tags-based-on-tag-attribute/10476>\
**Category:** Ignition\
**Created:** [September 16, 2015, 2:01pm UTC](https://forum.inductiveautomation.com/t/get-tags-based-on-tag-attribute/10476 "2015-09-16T14:01:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![son122](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@son122](https://forum.inductiveautomation.com/u/son122)\
**Post date:** [September 16, 2015, 2:01pm UTC](https://forum.inductiveautomation.com/t/get-tags-based-on-tag-attribute/10476/1 "2015-09-16T14:01:06Z")

</div>

I’m aware of using a Tag Driven Provider to query tags from an external database; however, due to scale, this isn’t a good option for us. Other option I tried is system.tag.browseTags and using the result set to continue filtering. This method crashed if there are too many tags. Basically I need to know all the tags that have alarms enabled or tags that have history enabled.

Having a very large tags system is the cause of the problem. What other options do I have?

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [September 16, 2015, 5:27pm UTC](https://forum.inductiveautomation.com/t/get-tags-based-on-tag-attribute/10476/2 "2015-09-16T17:27:19Z")

</div>

[quote=“son122”]I’m aware of using a Tag Driven Provider to query tags from an external database; however, due to scale, this isn’t a good option for us. Other option I tried is system.tag.browseTags and using the result set to continue filtering. This method crashed if there are too many tags. Basically I need to know all the tags that have alarms enabled or tags that have history enabled.

Having a very large tags system is the cause of the problem. What other options do I have?[/quote]

how many tags do you have?

I had wrote a short script to do this kind of thing when someone requested in the past.  
[inductiveautomation.com/forum/v … 25&t=13497](https://inductiveautomation.com/forum/viewtopic.php?f=25&t=13497)

also, how are your tags structured? is it alot of the same tag types in separate folder or just alot of different random tagnames?

one option that you could do is export them out in xml and see if you can figure out a way to filter them in the xml file.

another way would be to export them out in csv, then import the folder and tagname into a database table. then you could build a readAll script that looks at the alrm and history configs for each tag and builds you a list of tags with history/alarming setup.

---

<div class="post-metadata">

**Author:** ![son122](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@son122](https://forum.inductiveautomation.com/u/son122)\
**Post date:** [September 16, 2015, 7:08pm UTC](https://forum.inductiveautomation.com/t/get-tags-based-on-tag-attribute/10476/3 "2015-09-16T19:08:14Z")

</div>

Thanks. Over 100K.  
Still refining the tag structure to something more simpler, but the problem is there are a lot of moving pieces. Just changing structure breaks everything.

I like the idea of exporting them out to a database. One concern is syncing this process so that it is more automated. Otherwise, every time we add/delete/move a tag, the database is no longer feasible and need to be rerun all over again.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 16, 2015, 7:09pm UTC](https://forum.inductiveautomation.com/t/get-tags-based-on-tag-attribute/10476/4 "2015-09-16T19:09:21Z")

</div>

You can get the tags that have historical tracking from the sqlth\_te table:

```auto
SELECT * FROM sqlth_te
```

For the alarms, diat150’s script is a nice one, but it uses system.tag.browseTags, which you say you’re having issues using.

You might want to consider giving Nick Mudge’s [Power Scripting module](http://marketplace.inductiveautomation.com/moduledetail;jsessionid=920E4033A2A9F015FC2B99A5A1F100C0?0&moduleId=87) a try. Part of its functionality is that you can query the internal database (and the mutable datasets are pretty nice too! 😉 ) I believe the module runs the usual two hours in trial mode. $200 US if you decide to keep it.

Here are two variants of a script using the module:

[code]#Get List of tags ID with alarm configurations  
alarmTagIDquery = “SELECT DISTINCT TAGID FROM SQLTAGALARMPROP”  
alarmTagIDResult = pa.ignition.db.runPrepInternalDBQuery(alarmTagIDquery)

#Convert it to a list  
alarmTagIDList=[]  
for row in alarmTagIDResult:  
alarmTagIDList.append(row[0])

#Query the tags  
tagQuery = “SELECT \* FROM SQLTAG”  
tagResult = pa.ignition.db.runPrepInternalDBQuery(tagQuery)

#Filter the tag dataset againg the alarm tagID list  
tagResult.filterRows(lambda row: row[0] in alarmTagIDList )  
print tagResult  
[/code]

[code]#Get List of tags ID with alarm configurations  
alarmTagIDquery = “”“SELECT DISTINCT TAGID FROM SQLTAGALARMPROP”""  
alarmTagIDResult = pa.ignition.db.runPrepInternalDBQuery(alarmTagIDquery)

#Convert it to a list  
alarmTagIDList=[]  
for row in alarmTagIDResult:  
alarmTagIDList.append(row[0])

#Make a string of the list to use in tag query  
listString = ‘,’.join(str(e) for e in alarmTagIDList)

#Query the tags  
tagQuery = “SELECT \* FROM SQLTAG WHERE SQLTAG\_ID IN(”+listString+")"  
tagResult = pa.ignition.db.runPrepInternalDBQuery(tagQuery)

print tagResult[/code]
