# Bind runtime table data with SQL Query

**URL:** <https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009>\
**Category:** Ignition\
**Created:** [November 27, 2020, 9:43am UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009 "2020-11-27T09:43:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![david4](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@david4](https://forum.inductiveautomation.com/u/david4)\
**Post date:** [November 27, 2020, 9:43am UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/1 "2020-11-27T09:43:22Z")

</div>

Hello, I would like to ask if anyone knows how to associate a SQL query generated by a script, to the data field of a table. So that the table updates automatically when the database is changed.

What I would like is a method that allows me to run a script whenever the table decides to re-query the db.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 27, 2020, 12:37pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/2 "2020-11-27T12:37:01Z")

</div>

So currently you have a table component whose `data` property is bound to a sql query binding? Or is it not bound and populated instead by the script?

If it’s of any relevance, you can call the `system.db.refresh` (vision) or the `refreshBinding` component method (perspective)

Are you using vision or perspective?

---

<div class="post-metadata">

**Author:** ![david4](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@david4](https://forum.inductiveautomation.com/u/david4)\
**Post date:** [December 16, 2020, 9:49am UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/3 "2020-12-16T09:49:16Z")

</div>

Hi, thanks for the answer.

I am currently using vision.  
I found a solution by adding a script to the page load event that performs the correct query and assigns the result’s dataset to the date field of the table.

This solves the problem, but every time an operation is performed, within the page, for example an insert through a simple form, so without reloading the page, I have to manually update the table again.

What i wanted was the ability to perform these updates automatically via polling, a bit like when you bind to a named query.

---

<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:** [December 16, 2020, 1:05pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/4 "2020-12-16T13:05:22Z")

</div>

Is your raw query not compatible with the Named Query system? It sounds like you want a script to “post-process” the raw data before assigning to the table. If so, add a custom dataset property to the table, bind your named query there, and use a propertyChange event script to convert the data whenever it arrives.

---

<div class="post-metadata">

**Author:** ![david4](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@david4](https://forum.inductiveautomation.com/u/david4)\
**Post date:** [December 16, 2020, 1:27pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/5 "2020-12-16T13:27:57Z")

</div>

Unfortunately not. I’ll explain better.

I created a configuration file external to ignition. Upon startup, the gateway reads it, and based on this file, certain columns of a table may be visible or not. Like various other properties.

By processing the configuration file i insert the list of visible columns in system.util.getGlobals (“myKey”). (“myKey” is for example).

The sql query for the table is therefore a function of this processing, and consequently of the global dictionary.

In named queries system i have no way to “write” code to retrieve this data.

---

<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:** [December 16, 2020, 1:31pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/6 "2020-12-16T13:31:18Z")

</div>

Actually, you do. The “queryString” parameter type is specifically for these odd cases where you need to supply some _structure_ to the query, not just _values_.

---

<div class="post-metadata">

**Author:** ![david4](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@david4](https://forum.inductiveautomation.com/u/david4)\
**Post date:** [December 16, 2020, 1:45pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/7 "2020-12-16T13:45:05Z")

</div>

Yes, but how do i pass the list inside the dictionary to the parameter value?

---

<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:** [December 16, 2020, 2:31pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/8 "2020-12-16T14:31:51Z")

</div>

You convert the dictionary to a string containing the SQL fragment your named query needs. Personally, I would put that in a string tag, not in the python globals. The caller of the named query would include the tag reference. If you need different configurations per Vision client, use a client tag.

---

<div class="post-metadata">

**Author:** ![david4](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@david4](https://forum.inductiveautomation.com/u/david4)\
**Post date:** [December 16, 2020, 3:24pm UTC](https://forum.inductiveautomation.com/t/bind-runtime-table-data-with-sql-query/41009/9 "2020-12-16T15:24:54Z")

</div>

Yes, is doable.

Thanks man
