# system.db.runScalarPrepQuery

**URL:** <https://forum.inductiveautomation.com/t/system-db-runscalarprepquery/43047>\
**Category:** Ignition\
**Created:** [February 5, 2021, 12:05am UTC](https://forum.inductiveautomation.com/t/system-db-runscalarprepquery/43047 "2021-02-05T00:05:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwalters1](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@rwalters1](https://forum.inductiveautomation.com/u/rwalters1)\
**Post date:** [February 5, 2021, 12:05am UTC](https://forum.inductiveautomation.com/t/system-db-runscalarprepquery/43047/1 "2021-02-05T00:05:42Z")

</div>

I would like to know why one of these lines of code works and the other does not-  
table = Postgres Database  
column\_1 = character varying  
column\_2 = integer  
column\_3 = integer

The following code returns the single and expected value from the table-

value = system.db.runScalarPrepQuery(“SELECT column\_1 FROM table WHERE column\_2 = 123 AND column\_3 = 456”)

This line of code, however does not. It returns the error: "Error: operator does not exist: integer = character varying.

value = system.db.runScalarPrepQuery(“SELECT column\_1 FROM table WHERE column\_2 = ? AND column\_3 = ?”, [partNumber, scrapCode])

The variables values are partNumber = 123 and scrapCode = 456

When they are “Hard Coded” it works, otherwise it errors-

---

<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:** [February 5, 2021, 12:59am UTC](https://forum.inductiveautomation.com/t/system-db-runscalarprepquery/43047/2 "2021-02-05T00:59:06Z")

</div>

Sounds like a type coercion problem, probably in the JDBC layer. What Ignition version and JDBC driver version do you have (and have you tried updating the driver? Ignition updates will _not_ update your drivers for you).

You could also try casting the value you’re substituting into the statement; see here: [https://www.postgresqltutorial.com/postgresql-cast/](https://www.postgresqltutorial.com/postgresql-cast/)

---

<div class="post-metadata">

**Author:** ![rwalters1](https://avatars.discourse-cdn.com/v4/letter/r/b9e5f3/32.png) [@rwalters1](https://forum.inductiveautomation.com/u/rwalters1)\
**Post date:** [February 5, 2021, 12:29pm UTC](https://forum.inductiveautomation.com/t/system-db-runscalarprepquery/43047/3 "2021-02-05T12:29:42Z")

</div>

PGriffith: Thank you for the reply- You got me thinking about the data types- So, I printed the types of both the partNumber and scrapCode- (Both are being pulled from a property value)-

partNumber was integer, but scrapCode was unicode-  
I set scrapCode = int(scrapCode)

That took care of the issue- Many thanks!-
