# Postgres Namedquery In Clause

**URL:** <https://forum.inductiveautomation.com/t/postgres-namedquery-in-clause/100046>\
**Category:** Ignition\
**Tags:** namedqueries, perspective\
**Created:** [December 19, 2024, 3:29pm UTC](https://forum.inductiveautomation.com/t/postgres-namedquery-in-clause/100046 "2024-12-19T15:29:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Delizee](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Alexandre\_Delizee](https://forum.inductiveautomation.com/u/Alexandre_Delizee)\
**Post date:** [December 19, 2024, 3:29pm UTC](https://forum.inductiveautomation.com/t/postgres-namedquery-in-clause/100046/1 "2024-12-19T15:29:28Z")

</div>

Hi everyone,

I'm currently in the process of creating a named query that will fetch valve\_data from a postgres database. This is done by running the following code:

`SELECT * FROM valve_data WHERE valve_name IN (:tags )`

For some reason this query isn't returning any value when I test it with the following value for :tags:  
`('CM_670BFV099030')`

But when I run this in the Postgres database itself it does return values. Is my syntax for the tags wrong? I think I tried every possible method.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2d11b3655e8e4e4b60a8dc5d81175722edd6522a.png)

If anyone has any idea..

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 19, 2024, 3:35pm UTC](https://forum.inductiveautomation.com/t/postgres-namedquery-in-clause/100046/2 "2024-12-19T15:35:21Z")

</div>

Trying to parameterize values for the `in` key word is troublesome. I think it is considered query structure and not just a value substitution. You would have to change the parameter from `value` to `queryString`. This is usually not recommended unless your parameters are sanitized (see SQL injection).

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 19, 2024, 3:46pm UTC](https://forum.inductiveautomation.com/t/postgres-namedquery-in-clause/100046/3 "2024-12-19T15:46:38Z")

</div>

Example

```python
select *
from table
where id in {values}

```

values = "(1,2,3)"

more info  
[Using a querystring parameter in a named query IN clause - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/using-a-querystring-parameter-in-a-named-query-in-clause/47534)

[Ignition Perspective Named Query with WHERE IN Clause - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/ignition-perspective-named-query-with-where-in-clause/34062/8)

---

<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:** [December 19, 2024, 4:58pm UTC](https://forum.inductiveautomation.com/t/postgres-namedquery-in-clause/100046/4 "2024-12-19T16:58:35Z")

</div>

Since you are using PostgreSQL, a competent database, you have another option, as long as you use a "prep" query via script instead of a Named Query. See this discussion:

> [@Taking a Dataset and Inserting it to a SQL temp table](https://forum.inductiveautomation.com/t/taking-a-dataset-and-inserting-it-to-a-sql-temp-table/83852/4):
>
> If you were using a competent database (the following is PostgreSQL), you can pass java arrays as arguments, and unnest() them in a FROM clause. For an example, I created a table in my psql forum playground called phrases, to be used in a join. When queried by itself, you get this dataset: "#NAMES" "prefix","suffix" "#TYPES" "str","I" "#ROWS","4" "Hello","1" "Good Bye","2" "Welcome to","3" "Whoa!","4" To go with that, in a custom property named lookups, I created the following unbound datase…
