# Add ability to change the database assigned to named queries

**URL:** <https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 20, 2022, 4:05am UTC](https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101 "2022-07-20T04:05:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 20, 2022, 4:05am UTC](https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101/1 "2022-07-20T04:05:59Z")

</div>

I have multiple projects on a gateway, each with their own databases to store e.g. audit data. I would like to configure a single named query to query the database I choose. At the moment it's super awkward as I have to create multiple duplicate named queries, one for each database, and then have one Table component in Perspective for each one, only showing the one selected. Very inefficient...

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 20, 2022, 12:05pm UTC](https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101/2 "2022-07-20T12:05:03Z")

</div>

There’s a special parameter type for selecting a datasource. If otherwise identical, only one NQ is needed.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 28, 2023, 7:15am UTC](https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101/3 "2023-07-28T07:15:15Z")

</div>

I realise I never got back to this, and am trying to do something similar again. When you said there was a special parameter type, I'm not sure what you mean(t)?

[https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery)

These are the only parameters:

> String path - The path to the Named Query to run. Note that this is the full path to the query, including any folders.
> 
> Dictionary[String, Any] parameters - A Python dictionary of parameters for the Named Query to use. [optional]
> 
> String tx - An transaction ID, obtained from [beginNamedQueryTransaction](https://docs.inductiveautomation.com/display/DOC81/system.db.beginNamedQueryTransaction). If blank, will not be part of a transaction. [optional]
> 
> Boolean getKey - Only used for Update Query types. A flag indicating whether or not the result should be the number of rows affected (getKey=0) or the newly generated key value that was created as a result of the update (getKey=1). Not all databases support automatic retrieval of generated keys. [optional]

In other db functions, there's a `database` parameter which you can use to set the database to query against, but there's no such thing in the named query function 😕

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [July 28, 2023, 10:53am UTC](https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101/4 "2023-07-28T10:53:44Z")

</div>

> [@nminchin](#):
>
> In other db functions, there's a `database` parameter which you can use to set the database to query against

In the dictionary parameters you can pass a data with key as "database" and value as the name of the database.  
In the named query set Database Connection to **Parameter** , don't add any extra parameter for "database".  
I hope I understood the requirement correctly 🤔

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 28, 2023, 10:56am UTC](https://forum.inductiveautomation.com/t/add-ability-to-change-the-database-assigned-to-named-queries/62101/5 "2023-07-28T10:56:54Z")

</div>

Oh right, yep, that makese sense. I didn't know the option was even there! Thanks all
