# Force system.tag.queryTagHistory() to use specific historian db

**URL:** <https://forum.inductiveautomation.com/t/force-system-tag-querytaghistory-to-use-specific-historian-db/97774>\
**Category:** Ignition\
**Created:** [October 25, 2024, 2:21pm UTC](https://forum.inductiveautomation.com/t/force-system-tag-querytaghistory-to-use-specific-historian-db/97774 "2024-10-25T14:21:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [October 25, 2024, 2:21pm UTC](https://forum.inductiveautomation.com/t/force-system-tag-querytaghistory-to-use-specific-historian-db/97774/1 "2024-10-25T14:21:00Z")

</div>

With system.tag.queryTagHistory() how can we force this API to use specific historian db to retrieve data?  
Sometimes for testing people assign tags to one DB and after a while, they change them to another DB. So the tag history data will be on both DBs.  
Even when I set the default DB in the tag provider, this API can't retrieve data and try to get the data from the first DB.  
The API accepts paths with tag provider names but no cue for historian DB. I believe it should use the default set db in the tag provider setting but it seems it doesn't care about it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 25, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/force-system-tag-querytaghistory-to-use-specific-historian-db/97774/2 "2024-10-25T14:34:04Z")

</div>

There are tag paths and history paths. If you give the historian a simple tag path, it will look up the tag's storage provider and convert to a local history path. If you want anything else, you need to provide a history path instead of a simple tag path.

See this topic:

> [@Is the extended tag path format for history queries documented?](https://forum.inductiveautomation.com/t/is-the-extended-tag-path-format-for-history-queries-documented/96730):
>
> I was doing some hackish things with a history DB, and landed in a situation where I could no longer see the history for one specific tag using system.tag.queryTagHistory. Just to make sure I wasn't fumbling a parameter, I tried a history binding in Perspective for the same tag and it worked. Then I noticed that the designer UI had built the tag path in a form I've never seen documented. I tried that path with queryTagHistory and it got data. I was using a more simple: my\_hist = system.tag.qu…

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [October 25, 2024, 5:39pm UTC](https://forum.inductiveautomation.com/t/force-system-tag-querytaghistory-to-use-specific-historian-db/97774/3 "2024-10-25T17:39:41Z")

</div>

Ok I know that but where we define the default tag's storage provider? If in tag provider config page, it doesn't work for me. That's my problem

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 25, 2024, 6:46pm UTC](https://forum.inductiveautomation.com/t/force-system-tag-querytaghistory-to-use-specific-historian-db/97774/4 "2024-10-25T18:46:46Z")

</div>

When you set up a Database as a Historical Provider it becomes available to the designer, as a selection in the history section of the tag editor (as you know).

If you want to look up history for a tag path on a different provider than what is set in the tag editor, then you will need to manually construct the Historical tag path with the correct Historical Provider.

Here is a little script I adapted that shows how to do it (aside from manual concatenation).

```python
def getHistoricalTagPath(path):
    from com.inductiveautomation.ignition.common import QualifiedPath, WellKnownPathTypes,QualifiedPathUtils
    from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

    qPath = QualifiedPathUtils.fromTagPathNew(TagPathParser.parseSafe('default',path))
    gateway = system.tag.readBlocking('[System]Gateway/SystemName'])
    driver = ':'.join([gateway.value,qPath.getPathComponent('prov')])
    return QualifiedPath.Builder().set(WellKnownPathTypes.HistoryProvider,'YourHistoryProvider').setDriver(driver).setTag(qPath.getPathComponent('tag')).build().toString()

```

You can find the original script and conversation here:

> [@Get the Historical Tag Path from the Tag Path](https://forum.inductiveautomation.com/t/get-the-historical-tag-path-from-the-tag-path/61981/6):
>
> So, the driver is actually part of the full tag path. It is possible if you are using remote tag providers to use a gateway message handler in conjunction with this function to get what you’re looking for. If you put this function in a shared script on the same gateway as the tag provider, then it should return your historical tag path. Inspired heavily from the script provided by @PGriffith def getHistoricalTagPath(path): from com.inductiveautomation.ignition.common import QualifiedPath,…
