# Historical data into sql database

**URL:** <https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992>\
**Category:** Ignition\
**Created:** [September 15, 2024, 7:09am UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992 "2024-09-15T07:09:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [September 15, 2024, 7:09am UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/1 "2024-09-15T07:09:30Z")

</div>

How can I dump historical time series data of selected tags for a given time range from a [table displayed](https://inductiveuniversity.com/videos/displaying-tag-history/8.1) into a database table of given name?

---

<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:** [September 15, 2024, 10:53am UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/2 "2024-09-15T10:53:41Z")

</div>

You write a script to do row by row inserts. (There's no magic wand for this in Ignition.)

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [September 15, 2024, 12:07pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/3 "2024-09-15T12:07:19Z")

</div>

Would have been a nice feature to have, which perhaps would have been easy for IA to implement! Just like transaction groups but on historical data rather than real time OPC tag values.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [September 15, 2024, 1:05pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/4 "2024-09-15T13:05:48Z")

</div>

Alternatively, is there a way to search the historian database for a set of tags, using sql queries to get a list of tag values in a given time range and write them in another table?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 15, 2024, 1:08pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/5 "2024-09-15T13:08:18Z")

</div>

> **[system.tag.queryTagHistory | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory)**
>
> Issues a query to the Tag Historian.

> **[Ignition Database Table Reference | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/reference-pages/ignition-database-table-reference)**
>
> Ignition has a lot of systems built-in that will query the database automatically without requiring you to build a query. These systems automatically create the necessary tables in the database, insert the relevant data, and even query it back out...

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [September 15, 2024, 1:18pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/6 "2024-09-15T13:18:37Z")

</div>

Wow this is what I was looking for! I will read it further and see how to uses these functions to achieve my results. Hope values will be interpolated wherever not available. I don't know what's the granularity of t\_stamp, is it only stored time stamp or at regular interval. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [September 15, 2024, 2:02pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/7 "2024-09-15T14:02:37Z")

</div>

Read the documentation it clarifies all my doubts! Great! well thought out and well documented function! However, building the list of tags will have to be hard coded. Building drag and drop like in charts or table would be missing (or built!). Great feature useful for a lot of use cases!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 15, 2024, 2:02pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/8 "2024-09-15T14:02:41Z")

</div>

> [@prafull\_j](#):
>
> I don't know what's the granularity of t\_stamp, is it only stored time stamp or at regular interval.

It depends on the settings in the tag history definition. I suggest that you experiment with this and gain some understanding of how historian stores and compresses data. It's kind of tricky and some of its limitations include not doing any interpolation to get the estimated value at the bounds of the period of interest.

If, for example, you want values of a process variable or counter on the hour (or minute or ten minutes, etc.) then historian will disappoint. In this case I recommend creating gateway scheduled events. Project Browser | Scripting | Gateway Events | Scripting. See [Gateway Event Scripts | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#gateway-event-scripts-overview).

As an aid to seeing how historian is working I suggest that you create a Perspective view with a couple of datetime selectors and a table. Add a [Tag History binding](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/tag-history-bindings-in-perspective#tag-history-binding) on the table's `PROPS.data`. Set Query Mode to "AsStored". Set the Time Range to "Historical" and bind the Start Date and End Date to the datetime selectors.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [September 15, 2024, 2:07pm UTC](https://forum.inductiveautomation.com/t/historical-data-into-sql-database/95992/9 "2024-09-15T14:07:59Z")

</div>

Yes, thanks for your valuable tips, very useful. I don't want to generate this based on event triggers like time bound etc, I want to generate it on demand when users clicks a button etc. But may be event triggered reports will also be required sometimes. Thanks a lot indeed. IA has put in a lot of thought is building the scripting functions!
