# Extend named query with a query

**URL:** <https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 27, 2025, 3:14pm UTC](https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312 "2025-03-27T15:14:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [March 27, 2025, 3:14pm UTC](https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312/1 "2025-03-27T15:14:54Z")

</div>

Hello!

Would it be possible to extend a named query without changing the original query?

For example I would like add extension similar to:

```python
SELECT
TS.Codigo AS Code,
SUM(ROUND(TM.kwhGEN,0)) AS kWh_GEN,
SUM(ROUND(TM.kwhSAI,0)) AS kWh_SAI,
avg(TM.kwGEN) AS avg_kW_GEN,
avg(TM.PUE) AS PUE      
FROM T_Medidas_TE TM INNER JOIN T_Sede TS
ON TM.id_sede=TS.id_sede
WHERE TS.id_tipo NOT IN ('1','4','5')

```

Or it´s quicker make a new query?

Thanks!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 27, 2025, 3:30pm UTC](https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312/2 "2025-03-27T15:30:00Z")

</div>

> [@Alejandro\_Alaco](#):
>
> Would it be possible to extend a named query without changing the original query?

I'm not sure exactly what you're trying to get at by this, but it isn't possible to change a named query from outside of the Authoring Tab.

If you need dynamic queries then the best practice is to avoid Named Queries and use a scripted query with `system.db.runPrep*Query()`

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [March 27, 2025, 3:33pm UTC](https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312/3 "2025-03-27T15:33:19Z")

</div>

Ok, thanks @lrose I would just make a new one.

I was adapting a Vision project, and it seem they were extending the query somehow.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 27, 2025, 3:40pm UTC](https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312/4 "2025-03-27T15:40:50Z")

</div>

> [@Alejandro\_Alaco](#):
>
> they were extending the query somehow

Was it a NamedQuery? If so can you show the actual named query?

Technically, you can use a QueryString parameter to provide query text, but that is a security hole and IMO should be avoided when other tools offer a reasonable alternative.

Take a look at this for more information:

> [@runNamedQuery vs runPrepQuery](https://forum.inductiveautomation.com/t/runnamedquery-vs-runprepquery/81268/6):
>
> The original purpose of Named Queries was to make it possible to pass values into Vision Query bindings in a secure and efficient way, solving the unreliability of parameter stringification (looking at you, java.util.Date), and allowing the huge "legacy DB access" security hole to be closed. The maintenance advantages of NQs can be matched by multi-line strings for SQL in library scripts, so I tend to discount that item. However, not all is well. Some things to consider: NQs permit the use…

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [March 27, 2025, 3:50pm UTC](https://forum.inductiveautomation.com/t/extend-named-query-with-a-query/104312/5 "2025-03-27T15:50:20Z")

</div>

Thanks for the clarification
