# Issue running a SQL Delete

**URL:** <https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668>\
**Category:** Ignition\
**Created:** [February 19, 2019, 12:12pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668 "2019-02-19T12:12:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![keith.hyder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/keith.hyder/32/4909_2.png) [@keith.hyder](https://forum.inductiveautomation.com/u/keith.hyder)\
**Post date:** [February 19, 2019, 12:12pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/1 "2019-02-19T12:12:48Z")

</div>

I have a Power Table in my window. I am populating it using scripting and some variables. What I want to do next is have the ability to select a row in the table click a button and delete the row from the SQL database. I keep getting an error when I try this.

````auto
     number = system.tag.read("[Client]Delete_Number").value

     system.tag.write("[Client]Delete_Number",number)
     query = 'DELETE FROM SF_Paint_Schedule WHERE UID = ?'
     args = (number)
     system.db.runPrepUpdate(query,args) ```

This is the error I get. I notice it is doing some crazy stuff withe the variable. it should be 12.

Traceback (most recent call last):

  File "<event:actionPerformed>", line 8, in <module>

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(DELETE FROM SF_Paint_Schedule WHERE UID = "?", [0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], , , false, false)

	caused by Exception: Error executing system.db.runPrepUpdate(DELETE FROM SF_Paint_Schedule WHERE UID = "?", [0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], , , false, false)
	caused by GatewayException: SQL error for "DELETE FROM SF_Paint_Schedule WHERE UID = "?"": The index 1 is out of range.
	caused by SQLServerException: The index 1 is out of range.

Ignition v7.9.9 (b2018081621)
Java: Oracle Corporation 1.8.0_181

Thanks in advance for the help.
````

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 19, 2019, 12:58pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/2 "2019-02-19T12:58:57Z")

</div>

The args parameter should be a list according to the documentation.

Try the following and see if it works:

```auto
query = 'DELETE FROM SF_Paint_Schedule WHERE UID = ?'
args = [number]
system.db.runPrepUpdate(query,args)

```

---

<div class="post-metadata">

**Author:** ![keith.hyder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/keith.hyder/32/4909_2.png) [@keith.hyder](https://forum.inductiveautomation.com/u/keith.hyder)\
**Post date:** [February 19, 2019, 1:42pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/3 "2019-02-19T13:42:21Z")

</div>

Perfect that done the trick.Thanks

---

<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:** [February 19, 2019, 1:44pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/4 "2019-02-19T13:44:23Z")

</div>

It wasn’t a tuple. Parentheses around a single expression will not be a tuple. There must be at least one comma. A trailing comma inside the parentheses would make it a tuple, and it would have worked.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 19, 2019, 1:48pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/5 "2019-02-19T13:48:17Z")

</div>

My mistake, I have corrected the post so that others will not be misled.

Thanks for the correction.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [February 19, 2019, 2:50pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/6 "2019-02-19T14:50:27Z")

</div>

> [@pturmel](#):
>
> Parentheses around a single expression will not be a tuple. There must be at least one comma.

So much for PEP20 "Readability counts."

> **[PEP 20 – The Zen of Python | peps.python.org](https://peps.python.org/pep-0020/)**
>
> Python Enhancement Proposals (PEPs)

---

<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:** [February 19, 2019, 6:34pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/7 "2019-02-19T18:34:20Z")

</div>

> [@Sanderd17](#):
>
> So much for PEP20 “Readability counts.”

Indeed. Parentheses are understood pretty much everywhere as expression grouping. Not so much for tuples. It is the comma that makes a tuple, and will do so without the parentheses if otherwise unambiguous. The parentheses are often needed to disambiguate, but leads to magical thinking. Try this yourself:

```auto
>>> my_var = 1, 2, 3
>>> my_var
(1, 2, 3)
>>>

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 20, 2019, 9:38pm UTC](https://forum.inductiveautomation.com/t/issue-running-a-sql-delete/22668/8 "2019-02-20T21:38:23Z")

</div>

The real confusing part for me, and why initially I got this wrong in this thread is because, you need the parenthesis in certain situations. The main one being to create an empty tuple, which uses only the parenthesis.

Interestingly enough if you declare an empty tuple and then try to print the type out like this:

```auto
my_var = ()
print type(my_var)

```

It actually throws an error stating that my\_var is not declared.

They kind of missed the mark on this one imo.

My new found understanding that tuples are created using commas will help a lot going forward so I suppose I’ve gained that much out of this discussion.
