# Regular Tag Sampling to Local PostgreSQL for ML Processing

**URL:** <https://forum.inductiveautomation.com/t/regular-tag-sampling-to-local-postgresql-for-ml-processing/104652>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [April 3, 2025, 2:48pm UTC](https://forum.inductiveautomation.com/t/regular-tag-sampling-to-local-postgresql-for-ml-processing/104652 "2025-04-03T14:48:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asjal\_Ahmad](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Asjal\_Ahmad](https://forum.inductiveautomation.com/u/Asjal_Ahmad)\
**Post date:** [April 3, 2025, 2:48pm UTC](https://forum.inductiveautomation.com/t/regular-tag-sampling-to-local-postgresql-for-ml-processing/104652/1 "2025-04-03T14:48:59Z")

</div>

Hi all,

I'm setting up an ML backend on the same machine running the Ignition gateway service. The gateway machine has its own local PostgreSQL database. I want to periodically sample data from tags (pumps, valves, flowmeters, etc.) into local PostgreSQL views/tables, so the local ML backend (running in Docker on the same machine) can process it. I cannot use SQL Bridge module.

How can I achieve this?

---

<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:** [April 3, 2025, 2:54pm UTC](https://forum.inductiveautomation.com/t/regular-tag-sampling-to-local-postgresql-for-ml-processing/104652/2 "2025-04-03T14:54:37Z")

</div>

Write script functions in the project library called from either a gateway timer event or a gateway scheduled event. The function(s) would have the following basic structure:

- Use `system.tag.readBlocking()` and/or `system.opc.readValues()` to acquire fresh data. The list of tag paths and/or OPC item paths can be a script top-level constant initialized outside any function.

- Use `system.db.runPrepUpdate()` to run the INSERT on the database, where `?` parameters are placed in the SQL where the raw data needs to be, and the raw data is supplied as the parameters list to that system function. If you are always using the same list of tags/OPC items, you can make the SQL template a script top-level constant, too.

---

<div class="post-metadata">

**Author:** ![Asjal\_Ahmad](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@Asjal\_Ahmad](https://forum.inductiveautomation.com/u/Asjal_Ahmad)\
**Post date:** [April 3, 2025, 3:04pm UTC](https://forum.inductiveautomation.com/t/regular-tag-sampling-to-local-postgresql-for-ml-processing/104652/3 "2025-04-03T15:04:41Z")

</div>

I was hoping it wouldn't come to that. Unfortunately, it seems like it is the only solution

---

<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:** [April 3, 2025, 3:41pm UTC](https://forum.inductiveautomation.com/t/regular-tag-sampling-to-local-postgresql-for-ml-processing/104652/4 "2025-04-03T15:41:59Z")

</div>

Well, the simple method is to use the SQL Bridge module. But you said you cannot. 🤷‍♂️
