# SQL Query with Parameters, postgresql 15, syntax error

**URL:** <https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296>\
**Category:** Ignition\
**Tags:** reporting, perspective, database, ignition81\
**Created:** [June 24, 2024, 7:28pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296 "2024-06-24T19:28:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Hoover](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Josh\_Hoover](https://forum.inductiveautomation.com/u/Josh_Hoover)\
**Post date:** [June 24, 2024, 7:28pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296/1 "2024-06-24T19:28:41Z")

</div>

Hello,

I am querying a postgres db and trying to add a parameter, which isn't working. I'm getting the syntax error that I've attached a pic of. I've followed the instructions in the manual, but still no data. I feel like this must be something simple I'm missing.  
 ![Snag_240eca85](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/80f3f1ed19379e479abbc8fde8a4d3ee708faa68.png)  
 ![Snag_240ee1c6](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1e030551a209c2b8596e89e789853fc61ad6250a.png)  
 ![Snag_240eef43](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/4/94e912434062bc35f4a1db6ace01aacd2a135c09.png)

 ![Snag_240f081a](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/3/13979e7940821fcf2518e447225d61908e4000c1.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 24, 2024, 7:38pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296/2 "2024-06-24T19:38:46Z")

</div>

In standard SQL queries, like named queries, parameters cannot be used to substitute _structural_ elements of a query - only parameters within e.g. a WHERE clause. You can technically get around this limitation with the 'Basic SQL Query' type: [Basic SQL Query | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/reporting/report-data/basic-sql-query), but it's better overall to not have a need for dynamic queries in the first place.

---

<div class="post-metadata">

**Author:** ![Josh\_Hoover](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@Josh\_Hoover](https://forum.inductiveautomation.com/u/Josh_Hoover)\
**Post date:** [June 24, 2024, 7:43pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296/3 "2024-06-24T19:43:29Z")

</div>

Thanks for the response. I need to be able to select between a lot of different db tables, not sure of another way to do that.

---

<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:** [June 24, 2024, 8:02pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296/4 "2024-06-24T20:02:27Z")

</div>

I would use a scripted data source and use that to build the query dynamically, then execute it using `system.db.runPrepQuery()`

---

<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:** [August 11, 2024, 2:04pm UTC](https://forum.inductiveautomation.com/t/sql-query-with-parameters-postgresql-15-syntax-error/92296/6 "2024-08-11T14:04:31Z")

</div>

Is your question actually related to this topic? If not, delete this and start a new topic for your question. Then provide more information (actual SQL and script content).
