Named Query Not Working after 8.1.27 upgrade

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

Error Message

Desired Output
image

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

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.

1 Like

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.

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.

1 Like

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.

2 Likes

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

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

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.

3 Likes

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:

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
2 Likes

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.

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. :man_shrugging:

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.)

2 Likes

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

For exactly this reason. Not keen on a new dependency just for this.

3 Likes

Not to mention if you right click any named query you can add documentation if needed -
image

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

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!

1 Like