# \[Bug-2887\] Issue with commented parameter binding with Postgres (maybe others)

**URL:** <https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831>\
**Category:** Ignition\
**Tags:** namedqueries, ignition81\
**Created:** [May 20, 2022, 11:21am UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831 "2022-05-20T11:21:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielAbdelsamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danielabdelsamed/32/34878_2.png) [@DanielAbdelsamed](https://forum.inductiveautomation.com/u/DanielAbdelsamed)\
**Post date:** [May 20, 2022, 11:21am UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/1 "2022-05-20T11:21:37Z")

</div>

When creating a named query, having parts of the query commented out can be useful. Especially during debugging and for helping other developers.

When a parameter is referenced within a query (non-commented), then also in a comment, the query fails. Example:

```auto
-- SELECT :id as fail

SELECT :id

```

Where `:id` is a parameter that is a String. Value does not matter as it fails during parsing. When executing the query on the test screen, the following error is presented:

```auto
org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1.

```

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

I have been using Postgres for quite some time, and I suspect that the way ignition is pre-parsing the query string is inconsistent with Postgres. Note how the error states it is being passed two parameters, but is only expecting one. I believe Ignition is parsing the commented parameter, when it should be ignored.

To summarize:

**Expected Behavior**  
The following query parses and properly runs in Postgres

```auto
-- SELECT :id as fail

SELECT :id

```

**Actual Behavior**  
Postgres rejects the query due to parameter mismatch

---

<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:** [May 20, 2022, 12:11pm UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/2 "2022-05-20T12:11:43Z")

</div>

JDBC is not equivalent to your database’s management studio. Comments are part of SQL _ **scripting** _, where JDBC works on **single** SQL _ **statements** _. Some JDBC drivers implement some SQL scripting support, but it is not widespread.

This isn’t something Ignition is imposing, it is just the way JDBC works. Ignition doesn’t pre-parse except for trivial injection of TOP or LIMIT clauses.

Don’t use comments. Don’t use DECLARE or script parameters.

---

<div class="post-metadata">

**Author:** ![DanielAbdelsamed](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/danielabdelsamed/32/34878_2.png) [@DanielAbdelsamed](https://forum.inductiveautomation.com/u/DanielAbdelsamed)\
**Post date:** [May 20, 2022, 12:33pm UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/3 "2022-05-20T12:33:29Z")

</div>

I get Ignition’s JDBC runs in single statement mode. The recommendation to just not use comments really doesn’t work with complex queries, future developers would cry 🙂 . Comments work just fine with the Postgres driver, just the parameters therein causing an issue.

Are you sure about Ignition not doing pre-parsing? AFAIK, JDBC only supports `?` and `??` for parameters, and all implementations of named parameters are managed by custom pre-parsing or a higher level JDBC library. Ex. NamedParameterJdbcTemplate from Spring

If there is any way to do a pre-check for it, it would provide for easier debugging. My co-worker spent a while trying to fix this bug and we eventually discovered it was the comment. Generally I would assume the _last_ issue it could possibly be would be a comment.

If this would be better to post to the ideas page, let me know.

---

<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:** [May 20, 2022, 12:39pm UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/4 "2022-05-20T12:39:52Z")

</div>

> [@DanielAbdelsamed](#):
>
> Are you sure about Ignition not doing pre-parsing?

Simple string search and substitution. (Well, allowing for quoted strings.} Noting where they are substituted to construct the correct order for the question marks. It is not a SQL-aware parser, so has no recognition of comments.

---

<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:** [May 20, 2022, 12:41pm UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/5 "2022-05-20T12:41:57Z")

</div>

> [@DanielAbdelsamed](#):
>
> If this would be better to post to the ideas page, let me know.

It doesn't hurt to ask. But don't hold your breath waiting for this.

---

<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:** [May 20, 2022, 12:43pm UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/6 "2022-05-20T12:43:55Z")

</div>

Perhaps a middle ground solution would be to allow the developer to leave comments on a named query in a separate text box akin to how custom properties on a component let you leave notes regarding what its there for.

---

<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:** [May 20, 2022, 2:38pm UTC](https://forum.inductiveautomation.com/t/bug-2887-issue-with-commented-parameter-binding-with-postgres-maybe-others/59831/7 "2022-05-20T14:38:07Z")

</div>

We’re treating this as a bug internally. Phil’s larger point is correct (we don’t, and won’t attempt to, truly parse your query) _but_ we’re planning to change things so that at least leading `--` are properly interpreted.
