# Question about named query updates vs selects

**URL:** <https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189>\
**Category:** Ignition\
**Created:** [September 14, 2023, 7:18pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189 "2023-09-14T19:18:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 14, 2023, 7:18pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/1 "2023-09-14T19:18:43Z")

</div>

> [@"Statement does not return results" Error on INSERT INTO script](https://forum.inductiveautomation.com/t/statement-does-not-return-results-error-on-insert-into-script/76009/2):
>
> Anything that isn't a SELECT needs to use `system.db.runPrepUpdate()`.

Is this a hard rule?

I observed that it still execute the named query Insert. ??

---

<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:** [September 14, 2023, 7:22pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/2 "2023-09-14T19:22:32Z")

</div>

You may be able to but I wouldn't advise it and there's no reason to go against this advice. Presumably when you insert, many times you want the id of the record you just inserted in case you need to use it elsewhere, and that's only possible with the `update` queries functions and leveraging the `getKey=1` kwarg.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 14, 2023, 7:32pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/3 "2023-09-14T19:32:45Z")

</div>

Thanks.  
My team expect to use named Query all the way.

I just read the manual on the command.

If I understood correct, the order of ? to list must be strictly in order?

---

<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:** [September 14, 2023, 7:35pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/4 "2023-09-14T19:35:23Z")

</div>

With named queries you still have to select whether its a "Query" (for SELECTs) or "Update Query" (for INSERT/UPDATE/DELETE) so that you can get the right info out - either a dataset for the SELECT, or the id/number of rows affects for the others depending on if yo use getKey or not.

Yes, the ? are filled in, in order, by your list of arguments, and the ? cannot be used for SQL keywords like the table name but only actual values. More about it in the documentation - [system.db.runPrepUpdate - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepUpdate)

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [September 14, 2023, 8:25pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/5 "2023-09-14T20:25:40Z")

</div>

when getKey=1  
the PrepUpdate command returned error "A result set was generated for update."

Otherwise when getKey=0  
PrepUpdate return -1 (what does -1 means)

---

<div class="post-metadata">

**Author:** ![Mason\_Stevens](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mason\_Stevens](https://forum.inductiveautomation.com/u/Mason_Stevens)\
**Post date:** [September 15, 2023, 12:24pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/6 "2023-09-15T12:24:53Z")

</div>

I'm still pretty new to Ignition but here's what it sounds like:

When getKey = 1, the query tries to return "the newly generated key _value_" i.e., it's attempting to return _one_ number but instead is getting an array or list as a "result set". If you've not assigned a Primary Key to the table you're updating, it may not know which column to treat as the key and so returns all columns, giving more values than it expects. Honestly, just a guess though.

I'm unsure what the -1 return means when getKey = 0. Usually, I've seen a -1 used as no-selection, like in the selected row component of a power table. I would think if no rows were affected, however, that getKey=0 would return 0, so maybe it means ALL rows? Even then I would think it would just return the actual row count. I'll try and do some testing to replicate.

---

<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:** [September 15, 2023, 1:24pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/7 "2023-09-15T13:24:13Z")

</div>

What is the query you are putting in your prepUpdate ststament? Share that

---

<div class="post-metadata">

**Author:** ![Mason\_Stevens](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mason\_Stevens](https://forum.inductiveautomation.com/u/Mason_Stevens)\
**Post date:** [September 15, 2023, 1:36pm UTC](https://forum.inductiveautomation.com/t/question-about-named-query-updates-vs-selects/79189/8 "2023-09-15T13:36:36Z")

</div>

Was also wondering about the query. I've been unable to reproduce either result.
