# Update query scripting

**URL:** <https://forum.inductiveautomation.com/t/update-query-scripting/79517>\
**Category:** Ignition\
**Tags:** scripting, database\
**Created:** [September 22, 2023, 4:50pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517 "2023-09-22T16:50:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 22, 2023, 4:50pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/1 "2023-09-22T16:50:45Z")

</div>

this query runs fine in query browser

`UPDATE DEVICESETTINGS SET DESCRIPTION = 'adfasfasdfdsaf' WHERE name = 'AmJE01'`

but when i try to run the same thing in the script console

```auto
updatequery = "UPDATE DEVICESETTINGS SET DESCRIPTION = ? WHERE name = ?"
args = ["adfasfasdfdsaf","AmJE01"]
database = "IgnitionPostgresDB"
system.db.runPrepQuery(updatequery, args, database)

```

I get all kinds of errors.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 22, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/2 "2023-09-22T16:57:12Z")

</div>

> [@Brandon\_Dixon](#):
>
> system.db.runPrepQuery(updatequery, args, database)

use `runPrepUpdate` instead.

and use the code formatting tool when you want to post code:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/2/824b28bfe9da0c117eea2e909cfddc4a1a42ee74.png)

edit:  
also:

> [@Brandon\_Dixon](#):
>
> ```auto
> Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
> Position: 59
> 
> ```

That might also be something to look into, but I ain't trying to debug non-formatted code.

---

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 27, 2023, 2:03pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/3 "2023-09-27T14:03:26Z")

</div>

Changed script to use runPrepUpdate

```auto
query = "UPDATE DEVICESETTINGS SET DESCRIPTION = ? WHERE name = ?"
args = ['adfasfasdfdsaf', 'AmJE01']
system.db.runPrepUpdate(query, args)

```

and I'm still getting errors

```auto
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 3, in <module>
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:268)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE DEVICESETTINGS SET DESCRIPTION = ? WHERE name = ?, [adfasfasdfdsaf, AmJE01], , , false, false)

	at org.python.core.Py.JavaError(Py.java:547)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:268)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)

	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:549)

	at org.python.core.PyObject. __call__ (PyObject.java:477)

	at org.python.core.PyObject. __call__ (PyObject.java:481)

	at org.python.pycode._pyx39.f$0(<input>:3)

	at org.python.pycode._pyx39.call_function(<input>)

	at org.python.core.PyTableCode.call(PyTableCode.java:173)

	at org.python.core.PyCode.call(PyCode.java:18)

	at org.python.core.Py.runCode(Py.java:1687)

	at org.python.core.Py.exec(Py.java:1731)

	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:611)

	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:599)

	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

	at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE DEVICESETTINGS SET DESCRIPTION = ? WHERE name = ?, [adfasfasdfdsaf, AmJE01], , , false, false)

	... 26 more

Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Cannot run this function when in read-only mode.

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.getResponse(GatewayInterface.java:384)

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:283)

	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:278)

	at com.inductiveautomation.ignition.client.script.ClientDBUtilities._runPrepStmt(ClientDBUtilities.java:288)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:261)

	... 24 more

Traceback (most recent call last):
  File "<input>", line 3, in <module>
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)

	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepUpdate(AbstractDBUtilities.java:268)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(UPDATE DEVICESETTINGS SET DESCRIPTION = ? WHERE name = ?, [adfasfasdfdsaf, AmJE01], , , false, false)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 27, 2023, 2:05pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/4 "2023-09-27T14:05:53Z")

</div>

> [@Brandon\_Dixon](#):
>
> `Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Cannot run this function when in read-only mode.`

click on this icon:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/b/ab0b7baf19cfc8c0609ab60361378d0605090d4a.png)  
to set write mode.

or in the project menu:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/8/881ebeeb895cab1c7653614de08440e015e040ec.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 27, 2023, 3:20pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/5 "2023-09-27T15:20:54Z")

</div>

Still getting

```auto
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: SQL error for "UPDATE DEVICESETTINGS SET DESCRIPTION = ? WHERE name = ?": ERROR: relation "devicesettings" does not exist

```

When running this query

`update DEVICESETTINGS set DESCRIPTION='asdfasdfsadfsa' where NAME='AmJE01'`

at this igntion page

`http://x.x.x.x/web/status/sys.internaldb`

But when i run the same query in perspective using the query browser I get the errors. After looking at the tables listed in the Perspective query browser DEVICESETTINGS is not listed, I think my issue is that I'm querying the wrong database.

Is there a separate database which stores DEVICESETTINGS vs what the script console sees?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 27, 2023, 11:39pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/6 "2023-09-27T23:39:12Z")

</div>

> [@Brandon\_Dixon](#):
>
> [http://x.x.x.x/web/status/sys.internaldb](http://x.x.x.x/web/status/sys.internaldb)

I feel like we've gotten way off course here. What are we actually trying to accomplish with this approach? I'm certain that if we understood that, we could guide you better. It also seems probable that we could do it without a query.

---

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 27, 2023, 11:52pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/7 "2023-09-27T23:52:23Z")

</div>

I'm trying to update the device descriptions using scripting

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2023, 12:50am UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/8 "2023-09-28T00:50:14Z")

</div>

> [@Brandon\_Dixon](#):
>
> device descriptions

Forgive me, but for some reason this just isn't clicking in my brain. Can you give me a specific example?

---

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 28, 2023, 1:37am UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/9 "2023-09-28T01:37:40Z")

</div>

I want to be able to update this Description column using scripting

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 28, 2023, 3:48am UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/10 "2023-09-28T03:48:29Z")

</div>

Dynamically? Do you actually need that?  
Why are you trying to do so via the web interface/what lead you to think that was a good idea?

If this is a one-time operation for setting up a system, perhaps [`system.device.addDevice`](https://docs.inductiveautomation.com/display/DOC81/system.device.addDevice) covers your needs?

---

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 28, 2023, 12:25pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/11 "2023-09-28T12:25:14Z")

</div>

I only need it once. I looked at trying to add it during the system.device.addDevice command, but looking at the [system.device.addDevice - deviceProps Listing](https://docs.inductiveautomation.com/display/DOC81/system.device.addDevice+-+deviceProps+Listing#system.device.addDevicedevicePropsListing-ModbusRtuOverTcpandModbusTcpKeys), I don't see a property to set the Description property?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 28, 2023, 12:42pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/12 "2023-09-28T12:42:40Z")

</div>

> **Note:** The Description and Enabled properties may not be configured with this function, although a device connection could be disabled with a call to [system.device.setDeviceEnabled()](https://docs.inductiveautomation.com/display/DOC81/system.device.setDeviceEnabled) after creating the connection.

womp womp

edit: I don't think that's accurate though, looking at the implementation it seems the "description" key would be used.

---

<div class="post-metadata">

**Author:** ![Brandon\_Dixon](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@Brandon\_Dixon](https://forum.inductiveautomation.com/u/Brandon_Dixon)\
**Post date:** [September 28, 2023, 1:02pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/13 "2023-09-28T13:02:44Z")

</div>

So my new props looks like

```auto
nameID="AmAE01"
newProps = {"hostname":"172.16.24.90","port":502,"description":"bleh"}
system.device.addDevice(deviceType="ModbusTcp",deviceName=nameID,deviceProps=newProps)

```

it doesn't fill in description setings

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 28, 2023, 1:05pm UTC](https://forum.inductiveautomation.com/t/update-query-scripting/79517/14 "2023-09-28T13:05:49Z")

</div>

Try it as a named argument to `addDevice`, not part of the props dictionary.

edit: it's even documented! [system.device.addDevice - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.device.addDevice)
