Query Tags: Named Queries

Can named queries be used inside of query tags?

No, unfortunately.

Ok. I tried writing the query in the UDT to reference the Named Query in the example below with a parameter, but it doesn't seem to work.

EXECUTE NAMED QUERY 'MF1_Dashboard', 'shift/GetPreviousShift'
WITH PARAMETERS
	machine_id = {MachineID}

Thanks

Named queries are project scoped, tags are gateway scoped.

Isn't a valid SQL statement either. You will need to create the query with the proper select statements that use the parts of the UDT you want to query the SQL Database. See: Types of Tags | Ignition User Manual for more information about Query Tags.

UPDATED: I suggested using an expression tag with runScript to execute the named query in a script, but as @pturmel pointed out, not a good idea. Good explanation below.

Always learning.

Don't do this. Expression tags execute in a small thread pool, separate from but otherwise just like tag events. Any long-running database operation will tie up a thread from this pool. Get three such expressions at once, and ALL expression tags in the system will stall.

Queries that don't fit the very simple model in Query Tags need to be moved to a gateway event (in a project, not a tag event).

1 Like

Thanks for pointing this out @pturmel. A great example of what NOT to do then :sweat_smile:

If you are bent on using a named query, then just setup a gateway timer event to update your tags.

Yes, I just utilized the gateway timerevent
to update my tags. -Thanks