# Error writing value to a query tag

**URL:** <https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683>\
**Category:** Ignition\
**Created:** [September 15, 2020, 3:35am UTC](https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683 "2020-09-15T03:35:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 15, 2020, 3:35am UTC](https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683/1 "2020-09-15T03:35:16Z")

</div>

Hi,  
I have created a query tag reading value from a postgesSQL database.  
I can read the value correctly with 1sec update time, but I cannot write value to the tag. Error shown below.

"Error writing “1” to tag [default]dbPlant/Devices/Light/cmd\_manual Bad\_ReadOnly(“Tag value source does not support writing.”

The tag value source is “db”.  
Is it possible to write value to a query tag?

Thanks

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/848c30569b351577e401b7087264029d7c3c9dba.png)

---

<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, 2020, 12:20pm UTC](https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683/2 "2020-09-15T12:20:57Z")

</div>

No. You must write to the DB yourself (scripted, using the system.db.\* functions).

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 16, 2020, 10:41pm UTC](https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683/3 "2020-09-16T22:41:54Z")

</div>

Thanks. I will tried it.

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 16, 2020, 11:35pm UTC](https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683/4 "2020-09-16T23:35:34Z")

</div>

It works using the following script:  
system.db.runUpdateQuery(“UPDATE device SET cmd\_mode = ‘%s’ WHERE name = ‘%s’” % (queryValue, keyValue1), ‘dbPlant’)

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [September 16, 2020, 11:49pm UTC](https://forum.inductiveautomation.com/t/error-writing-value-to-a-query-tag/38683/5 "2020-09-16T23:49:47Z")

</div>

I haven’t tested this, but I imagine this also works:

```auto
queryString = "UPDATE device SET cmd_mode=? WHERE name=?"
params = [queryValue,keyValue1]
system.db.runPrepUpdate(queryString,params,'dbPlant')

```

There’s a variety of reasons this is probably better than concatenating the query and values yourself including security (sql injection) and maybe performance (I think there might be a caching thing that runPrepUpdate takes advantage of). Even if I’m wrong about the performance part, it’s still good practice to use runPrepUpdate/runPrepQuery when needed instead of runQuery/runUpdateQuery for security.
