# Read Only Mode SQL Query

**URL:** <https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281>\
**Category:** Ignition\
**Created:** [August 23, 2023, 1:07pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281 "2023-08-23T13:07:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Waller](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Luke\_Waller](https://forum.inductiveautomation.com/u/Luke_Waller)\
**Post date:** [August 23, 2023, 1:07pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/1 "2023-08-23T13:07:19Z")

</div>

Hello All,

I am new to Ignition so please excuse my ignorance. I am adding a project to an existing cell after taking the Core course. This cell I am adding to is a functioning cell and the project is a KPI board. I am using this as a way to learn the system and get my feet wet. The issue is that I am trying to Sum a Query from the existing database in this system. When I attempt this I get :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d0687061c57332bc00829ee938555ca5619dbb5d.png)

"Error running query: SUM SELECT "Holes Completed" FROM PartData\_Log Cannot run this function when in read-only mode."

I have read how to fix this but I am concerned about writing to the database. This KPI should only be reading from not writing to the database.

Without the SUM syntax it doesn't create this warning. I assume it has something to do with my syntax. Could someone enlighten me as to how to do a "SUM" without needing to write to the database?

Thank You

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 23, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/2 "2023-08-23T13:11:39Z")

</div>

1. Where are you calling this wuery? For instance if you're calling it in a system.db.runUpdateQuery it will think its a write query even if its not.

2. Think your query should be more like `SELECT SUM(myColumn) FROM PartData_LOG`, SUM should be in the SELECT clause and use the column name directly, not quoted otherwise you may be doing a SUM on a string literal.

Are you able to run SELECT SUM(mycolumn) FORM PartData\_Log in the designer database browser?

---

<div class="post-metadata">

**Author:** ![Luke\_Waller](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Luke\_Waller](https://forum.inductiveautomation.com/u/Luke_Waller)\
**Post date:** [August 23, 2023, 1:36pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/3 "2023-08-23T13:36:41Z")

</div>

Thanks for the quick reply. I am using the Database Query Browser to test by query:

SELECT  
SUM "Holes Completed" AS Holes\_Completed

FROM PartData\_Log

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 23, 2023, 1:37pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/4 "2023-08-23T13:37:54Z")

</div>

Did this run in your database query browser? That syntax still doesn't look right. What database are you using (MySQL, SQL Server, etc)

---

<div class="post-metadata">

**Author:** ![Luke\_Waller](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Luke\_Waller](https://forum.inductiveautomation.com/u/Luke_Waller)\
**Post date:** [August 23, 2023, 1:40pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/5 "2023-08-23T13:40:23Z")

</div>

We are using MSSQL. I have tried several methods. If I run: SELECT "Holes Completed" FROM PartData\_Log It will return a long list of the correct data, I just need to SUM it

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 23, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/6 "2023-08-23T13:42:06Z")

</div>

`SELECT SUM([Holes Completed]) FROM PartData_Log` is what I would expect it to look like.

---

<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:** [August 23, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/7 "2023-08-23T13:42:27Z")

</div>

Avoid spaces in database column names. Spaces are a constant source of issues and frustration.

Aside from that, you might want to take a look at the doc for the functions you're using...

Here, you'll need to use parentheses:

```sql
select
    sum(column) colum_name
from
    table

```

---

<div class="post-metadata">

**Author:** ![Luke\_Waller](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Luke\_Waller](https://forum.inductiveautomation.com/u/Luke_Waller)\
**Post date:** [August 23, 2023, 1:43pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/8 "2023-08-23T13:43:32Z")

</div>

> [@bkarabinchak.psi](#):
>
> SELECT SUM([Holes Completed]) FROM PartData\_Log

WORKED!! Brilliant! Thank You!!

---

<div class="post-metadata">

**Author:** ![Luke\_Waller](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Luke\_Waller](https://forum.inductiveautomation.com/u/Luke_Waller)\
**Post date:** [August 23, 2023, 1:44pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/9 "2023-08-23T13:44:06Z")

</div>

Thank You, Much appreciated

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 23, 2023, 1:46pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/10 "2023-08-23T13:46:11Z")

</div>

I would recommend if you're still in the design phase of your project to listen to his suggestion about avoiding whitespace in column names. White spaces in database column names will give you headaches that can be easily avoided with using a convention like camelCase or snake\_case and then stick to that.

---

<div class="post-metadata">

**Author:** ![Luke\_Waller](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Luke\_Waller](https://forum.inductiveautomation.com/u/Luke_Waller)\
**Post date:** [August 23, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/read-only-mode-sql-query/78281/11 "2023-08-23T13:48:12Z")

</div>

OK, Understood. Thanks for the help, these are really simple things getting me hung up at this point so thanks for the help.
