# Data from named query appears to be caching

**URL:** <https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576>\
**Category:** Ignition\
**Created:** [September 12, 2025, 1:53pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576 "2025-09-12T13:53:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mawi](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@mawi](https://forum.inductiveautomation.com/u/mawi)\
**Post date:** [September 12, 2025, 1:53pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/1 "2025-09-12T13:53:49Z")

</div>

I have an issue regarding data from a named query that appears to be caching, even though caching is not set.

I have an SFC that runs a loop, the loop has a 2-second delay, then if it’s “ok to do data verification” it calls a script which does the data verification. Once that is done, it returns to the delay and loops again

The data verification script does a named query and compares the result to the data in PLC tags.

This all works fine, But if we pause the loop while we update the data in the database and the PLC and then start the loop again, the data that the script is bringing back from the database is the old value. I have tried lengthening the timer, and I can see through SSMS that the data in the database has changed but the named query appears to have the old data.

The ‘Cache Query Results’ in the named query is not enabled

**Script (data verification)**

sourceFunction= usrFunc.functionName()  
strBatch = str(system.tag.readBlocking(['Batch/Data/selectedBatchID'])[0].value)  
intRecipe = system.tag.readBlocking(['Batch/Data/Recipe/RecipeID'])[0].value  
currStep = system.tag.readBlocking(['Batch/Sequence/Main/iState'])[0].value  
skipValidation = system.tag.readBlocking(['Batch/Sequence/Main/skipParamValid'])[0].value  
lineName = system.tag.readBlocking(['Batch/Sequence/lineName'])[0].value  
_#Query active parameters listed on DB_  
namedQuery = "SFC/get\_ActiveParams"  
dsActiveParams=system.dataset.toPyDataSet(system.db.runNamedQuery(namedQuery,{'line':lineName}))

```
*#Iterate DS to get mismatch between DB and OPC*
result = \[\]
**for** index, row **in** enumerate(dsActiveParams):
    *#Read OPC path and get formatted data*
    tries = 0
    tagRead = \[None\]
    **while** (tries <=3) **and** (tagRead\[0\] == None):
        tagRead = utils.opcReadValue(row\['TagUrlRead'\],0,opcServerName)
        tries += 1
    *#Compare erading against SP*
    matchEval = (str((row\['SetPoint'\])) == str(tagRead\[0\])) & ('Good' == str(tagRead\[1\].quality))
    **if** matchEval != True:
        evaluation = \['Tag: '+str(row\['Tag'\]),'DBValue: '+str(row\['SetPoint'\]),'FromPLC: '+str(tagRead\[0\]),'OPCQuality: '+str(tagRead\[1\].quality)\]
        result += \[evaluation\]

*#Function will return False or empty List if No Difference found*
**if** (len(result) != 0) **and** (skipValidation == 0):
    **if** listMismatch == False:
        **return** True
    **else** :
        **return** result
**else** :
    **if** listMismatch == False:
        **return** False
    **else** :
        **return** \[\]

```

**Named Query (SFC/get\_ActiveParams)**

**SELECT**  
[Tag],  
IIF([DataType] **LIKE**'String%', [StringSetPoint], CAST([NumericSetPoint] **AS** NVARCHAR(30))) **AS** [SetPoint],  
IIF([DataType] **LIKE**'String%', '', CAST([NumericLowLimit] **AS** NVARCHAR(30))) **AS** [LowLimit],  
IIF([DataType] **LIKE**'String%', '', CAST([NumericHighLimit] **AS** NVARCHAR(30))) **AS** [HighLimit],  
[TagUrlWrite],  
[TagUrlRead],  
[DataType]  
**FROM**  
[BatchData].[dbo].[Tag\_Parameter\_Active\_Data]  
**WHERE**  
LineName **LIKE** :line;

---

<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:** [September 12, 2025, 2:03pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/2 "2025-09-12T14:03:59Z")

</div>

Please edit your post and fix the formatting using the \</\> button. You've lost indentation and syntax highlighting on both your Python code and SQL query. See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![mawi](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@mawi](https://forum.inductiveautomation.com/u/mawi)\
**Post date:** [September 15, 2025, 2:59pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/3 "2025-09-15T14:59:12Z")

</div>

# **Formatted script and Named Query as requested**

```python
 	sourceFunction= usrFunc.functionName()
	strBatch = str(system.tag.readBlocking(['Batch/Data/selectedBatchID'])[0].value)
	intRecipe = system.tag.readBlocking(['Batch/Data/Recipe/RecipeID'])[0].value
	currStep = system.tag.readBlocking(['Batch/Sequence/Main/iState'])[0].value
	skipValidation = system.tag.readBlocking(['Batch/Sequence/Main/skipParamValid'])[0].value
	lineName = system.tag.readBlocking(['Batch/Sequence/lineName'])[0].value
	#Query active parameters listed on DB
	namedQuery = "SFC/get_ActiveParams"
	dsActiveParams=system.dataset.toPyDataSet(system.db.runNamedQuery(namedQuery,{'line':lineName}))
	
	#Iterate DS to get mismatch between DB and OPC
	result = []
	for index, row in enumerate(dsActiveParams):
		#Read OPC path and get formatted data
		tries = 0
		tagRead = [None]
		while (tries <=3) and (tagRead[0] == None):
			tagRead = utils.opcReadValue(row['TagUrlRead'],0,opcServerName)
			tries += 1
		#Compare erading against SP
		matchEval = (str((row['SetPoint'])) == str(tagRead[0])) & ('Good' == str(tagRead[1].quality))

		if matchEval != True:
			evaluation = ['Tag: '+str(row['Tag']),'DBValue: '+str(row['SetPoint']),'FromPLC: '+str(tagRead[0]),'OPCQuality: '+str(tagRead[1].quality)]
			result += [evaluation]
	#Testing system.util.getLogger('PLC Validation').info('Validation End ' + str(system.date.getMillis(system.date.now())))#Testing
	#Function will return False or empty List if No Difference found
	if (len(result) != 0) and (skipValidation == 0):
		if listMismatch == False:
			return True
		else:
			return result
	else:
		if listMismatch == False:
			return False
		else:
			return []

```

## Named Query

```python
SELECT 
    [Tag],
    IIF([DataType] LIKE 'String%', [StringSetPoint], CAST([NumericSetPoint] AS NVARCHAR(30))) AS [SetPoint],
    IIF([DataType] LIKE 'String%', '', CAST([NumericLowLimit] AS NVARCHAR(30))) AS [LowLimit],
    IIF([DataType] LIKE 'String%', '', CAST([NumericHighLimit] AS NVARCHAR(30))) AS [HighLimit],
    [TagUrlWrite],
    [TagUrlRead],
    [DataType]
FROM 
    [BatchData].[dbo].[Tag_Parameter_Active_Data]
WHERE 
    LineName LIKE :line;

```

---

<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:** [September 15, 2025, 3:18pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/4 "2025-09-15T15:18:18Z")

</div>

> [@Transistor](#):
>
> Please **edit your post** and fix the formatting

You posted it twice. The original mess is still there!  
I suggest you remove the code blocks from the original post to keep the thread tidy.

---

<div class="post-metadata">

**Author:** ![mawi](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@mawi](https://forum.inductiveautomation.com/u/mawi)\
**Post date:** [September 15, 2025, 3:33pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/5 "2025-09-15T15:33:44Z")

</div>

It will not let me edit the original post - I can edit my replies but not the original post

---

<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:** [September 15, 2025, 3:36pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/6 "2025-09-15T15:36:50Z")

</div>

Ah! OK. It may be something to do with your number of posts on the site determined by the forum.  
Don't worry about it.

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [September 15, 2025, 4:04pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/7 "2025-09-15T16:04:16Z")

</div>

Can you answer to those question:

- Did you validate the query output with a log?
- When updating the database, do you add lines, or you update the existing one?
- Did you restart the SFC after your last code change?

Recommendation: individual readBlocking and individual OPC read are expensive, combine them to have a single tag read and a single opc read

---

<div class="post-metadata">

**Author:** ![mawi](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@mawi](https://forum.inductiveautomation.com/u/mawi)\
**Post date:** [September 16, 2025, 8:59am UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/8 "2025-09-16T08:59:39Z")

</div>

- not sure what you mean by -

> [@calimero100582](#):
>
> validate the query output with a log

- When updating the database we update an existing row with an update query
- yes the SFC was restarted since the last code update. In fact the gateway has been restarted even.

---

<div class="post-metadata">

**Author:** ![calimero100582](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/calimero100582/32/18630_2.png) [@calimero100582](https://forum.inductiveautomation.com/u/calimero100582)\
**Post date:** [September 16, 2025, 12:35pm UTC](https://forum.inductiveautomation.com/t/data-from-named-query-appears-to-be-caching/110576/9 "2025-09-16T12:35:56Z")

</div>

Get a logger using system.util.getLogger, then do a logger.debugf(“some value I change in the database: %s”, str(dsActiveParams[0][5]))

> **[system.util.getLogger | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-util/system-util-getLogger)**
>
> Returns a Logger object that can be used to log messages to the console.
