# Named Query Not Working after 8.1.27 upgrade

**URL:** <https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180>\
**Category:** Ignition\
**Tags:** database, scripting, ignition81\
**Created:** [October 8, 2023, 11:14am UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180 "2023-10-08T11:14:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunprasath.v](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@arunprasath.v](https://forum.inductiveautomation.com/u/arunprasath.v)\
**Post date:** [October 8, 2023, 11:14am UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/1 "2023-10-08T11:14:37Z")

</div>

Hello !!  
After the upgrade from 8.1.19 to 8.1.27, some of named query is not working.  
Here the DB is PostgreSQL. In PGSQL, **--** are used for commenting a line.  
In the below screenshot **--** are inside the single quote mark. It should be considered as string.

**Note** : This query is working fine in the query browser.

Named Query

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/3/236b4b68b11c07aa8d8d8023cf5f7b2319b76fee.png)

Error Message

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

Desired Output  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37ac54856d4983fe20f0c0d29c2296e11ee614e4.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 8, 2023, 11:34am UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/2 "2023-10-08T11:34:56Z")

</div>

It looks like Ignition's interpreter is misinterpreting the `--`. Try,

```sql
SELECT CONCAT('-', '-0000-', '-') AS ...

```

Tip: post code rather than pictures of code so we can copy, test and edit. Be sure to use the \</\> button to format it properly.

---

<div class="post-metadata">

**Author:** ![arunprasath.v](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@arunprasath.v](https://forum.inductiveautomation.com/u/arunprasath.v)\
**Post date:** [October 8, 2023, 11:53am UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/3 "2023-10-08T11:53:09Z")

</div>

Thanks for the reply @Transistor !!  
The issue is not how to get the desired output.  
The issue is, It was working fine in the earlier version, now many placed in my project I need to do the changes, which is very time consuming work.  
I'm reaching out to the community to know if anyone faced such issue. Or any code fix can be given by Inductive Automation team for this.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [October 8, 2023, 11:55am UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/4 "2023-10-08T11:55:18Z")

</div>

If I recall there was an attempt at putting in the ability to parse comments in the named queries that ended up causing issues. This might be an example of this. IA would need to confirm for sure, but if you do what @Transistor is demonstrating in this exact scenario and it fixes the issue, then that is most likely the issue. You would either need to refactor how you are doing this task or upgrade to a later version that isn't affected by this bug.

---

<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:** [October 8, 2023, 12:07pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/5 "2023-10-08T12:07:43Z")

</div>

> [@bschroeder](#):
>
> or upgrade to a later version that isn't affected by this bug.

Yup. Comment parsing was taken back out. (I don't recall precisely which version, but pretty quickly.) It was an attempt to help people using SQL _ **scripts** _ from Ignition with the few JDBC drivers that tolerate them. Bad side effects.

JDBC natively has no idea what a SQL script is--it is only designed to handle single **statements**.

---

<div class="post-metadata">

**Author:** ![arunprasath.v](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@arunprasath.v](https://forum.inductiveautomation.com/u/arunprasath.v)\
**Post date:** [October 8, 2023, 12:09pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/6 "2023-10-08T12:09:55Z")

</div>

Yes @bschroeder, the solution suggestion by @Transistor is fixing the issue.

---

<div class="post-metadata">

**Author:** ![arunprasath.v](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@arunprasath.v](https://forum.inductiveautomation.com/u/arunprasath.v)\
**Post date:** [October 8, 2023, 12:15pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/7 "2023-10-08T12:15:42Z")

</div>

Thanks @pturmel, I'm going to raise the ticket to know the exact version.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 8, 2023, 12:30pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/8 "2023-10-08T12:30:27Z")

</div>

8.1.28.

### Databases

**IGN-6957: Named query comment parsing is too simple, fails to handle quoted strings**  
Fixed an issue where named queries that included double dash strings would fail to execute properly.

> [@Nightly 8.1 Changelogs - 2023](https://forum.inductiveautomation.com/t/nightly-8-1-changelogs-2023/68524/50):
>
> Nightly Changelog: 8.1.28-SNAPSHOT-b20230425 Tag Historian Databases IGN-6957: Named query comment parsing is too simple, fails to handle quoted strings Fixed an issue where named queries that included double dash strings would fail to execute properly. Foundation Launchers IGN-5830: Launcher's List/Card view option should persist Added persistent launcher view preference feature, saving and using the last selected view (card or list) to the launcher's JSON across restarts Gateway Netw…

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 9, 2023, 9:53am UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/9 "2023-10-09T09:53:43Z")

</div>

I would also recommend formatting that query so it can be read easily.

Im on my phone and to hard to type out your query from a screenshot, but I use formatting like:

```auto
SELECT
   1,
   2

UNION

SELECT
   Field1, 
   Field2
FROM
   table1 t1
   LEFT JOIN table2 t2
      ON t1.id = t2.t1_id
WHERE
   t1.tstamp BETWEEN this AND that
      AND
   t2.id = 1234

```

---

<div class="post-metadata">

**Author:** ![Chris\_Nathan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_nathan/32/45712_2.png) [@Chris\_Nathan](https://forum.inductiveautomation.com/u/Chris_Nathan)\
**Post date:** [October 10, 2023, 1:15pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/10 "2023-10-10T13:15:12Z")

</div>

You are correct. The SQL comment parsing logic was removed in version 8.1.28. We have created another ticket (IGN-7647) to explore a better mechanism for parsing out SQL 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:** [October 10, 2023, 1:31pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/11 "2023-10-10T13:31:40Z")

</div>

> [@Chris\_Nathan](#):
>
> o explore a better mechanism for parsing out SQL comments.

Or just don't? Ignition is built on vanilla JDBC, and vanilla JDBC doesn't support SQL scripts nor a SQL script's comments. You'll need a full SQL parser to reliably identify comments, and that parser will need to know the quirks of different branded implementations. 🤷‍♂️

I recommend marking that one "Won't fix" until JDBC formally adds support for this sort of thing. (Or adds support for colon delimited parameters, which tosses the issue back at the JDBC driver writers, where it belongs.)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 10, 2023, 1:33pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/12 "2023-10-10T13:33:52Z")

</div>

> [@pturmel](#):
>
> I recommend marking that one "Won't fix"

Hehe, this was my recommendation when we looked at this as well...

> [@pturmel](#):
>
> You'll need a full SQL parser to reliably identify comments

For exactly this reason. Not keen on a new dependency just 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:** [October 10, 2023, 1:35pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/13 "2023-10-10T13:35:53Z")

</div>

Not to mention if you right click any named query you can add documentation if needed -  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/1/c159796b2da7399b109fd437ee905e8e27f22c70.png)

---

<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:** [October 10, 2023, 1:36pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/14 "2023-10-10T13:36:24Z")

</div>

Actually, it should be marked "not a bug", as using SQL scripts in JDBC is unsupported, and works only by accident in selected drivers.

---

<div class="post-metadata">

**Author:** ![Chris\_Nathan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_nathan/32/45712_2.png) [@Chris\_Nathan](https://forum.inductiveautomation.com/u/Chris_Nathan)\
**Post date:** [October 10, 2023, 2:55pm UTC](https://forum.inductiveautomation.com/t/named-query-not-working-after-8-1-27-upgrade/80180/15 "2023-10-10T14:55:19Z")

</div>

Well, you hit the nail on the head there. I considered providing that additional commentary about the variety of different SQL variations and JDBC notes, but you got me covered there!

Yes, the ticket is rather low priority based on effort-reward. Thanks for keeping us honest, Phil!
