# Comments in named queries?

**URL:** <https://forum.inductiveautomation.com/t/comments-in-named-queries/53709>\
**Category:** Ignition\
**Tags:** perspective, ignition81, namedqueries\
**Created:** [December 2, 2021, 11:15pm UTC](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709 "2021-12-02T23:15:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvaught](https://avatars.discourse-cdn.com/v4/letter/r/b487fb/32.png) [@rvaught](https://forum.inductiveautomation.com/u/rvaught)\
**Post date:** [December 2, 2021, 11:15pm UTC](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709/1 "2021-12-02T23:15:46Z")

</div>

Have read several posts here that seem to clearly state that comments (in the SQL) cause problems, errors, index out of range etc.

I’m assuming this is still the case?

And that the (Settings) tab’s (Description) field is the next best and safest place to add, what would be, comments to your SQL?

---

<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:** [December 3, 2021, 12:18am UTC](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709/2 "2021-12-03T00:18:54Z")

</div>

Comments are fine, it’s just that our parser is (currently) too dumb to distinguish a commented _parameter_ from a legitimate one, so:

```sql
SELECT * FROM TABLE WHERE 
A = :param
--AND B = :param2

```

_Should_ be fine, but is what currently throws an error, because the parser thinks it needs an additional value for `param2`.

---

<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:** [December 3, 2021, 1:24am UTC](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709/3 "2021-12-03T01:24:23Z")

</div>

Well, the JDBC spec does not explicitly say comments are allowed, just that at least single statements are accepted. Some drivers accept more, or even SQL scripts.

---

<div class="post-metadata">

**Author:** ![Inken\_Kestler](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@Inken\_Kestler](https://forum.inductiveautomation.com/u/Inken_Kestler)\
**Post date:** [June 26, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709/4 "2024-06-26T12:22:22Z")

</div>

Hi togehter,  
I found this topic, because suddenly I had the same issue.  
I have a small script in a Named query where I have a comment with an existing param, I have already used at another line in this script (:varOrderNumber).

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

It worked fine the last months (Ignition version 8.1.25)  
Today I noticed, that the query faults with the error message: "The index 3 is out of range."

As you mentioned,I can get rid of this error by deleting the comment.  
But contrary to what you described, changing the param to an unknown param like :abc does also work.

The only thing I changed in the last days: I updated our gateway to version 8.1.33.  
Could it be, that this caused my problem ?

Now I have to control every script, if I have a comment with an existing param.  
I thought an update would improve the performance and offers new features instead of additional bugs.

The issue is known for 3 years and still exists 😮

Sometimes Ignition causes a lot of gray hairs.

---

<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:** [June 26, 2024, 12:31pm UTC](https://forum.inductiveautomation.com/t/comments-in-named-queries/53709/5 "2024-06-26T12:31:08Z")

</div>

IA attempted to fix the parser to skip comments, but it broke other people's legitimate single-statement, standard JDBC queries. So that was reverted. 8.1.25 must be in the middle of that version span.

JDBC does not support SQL scripts. Some JDBC drivers do. JDBC does not support colon-delimited named parameters. Ignition's Named Query system patches colon-delimited parameters to be question marks and assembles the values for them in order. Anything less than a full brand-specific SQL language parser will have problems doing that _conditionally_.

Don't expect this to ever be fixed in Ignition. Don't use features of SQL _ **scripts** _, like comments, in Ignition, if you wish to future-proof your code.

Hopefully, some future JDBC spec will provide tools for named parameters, but I wouldn't hold my breath waiting.
