# Report Sql Data source Postgres DB. Cannot run query with parameters

**URL:** <https://forum.inductiveautomation.com/t/report-sql-data-source-postgres-db-cannot-run-query-with-parameters/61923>\
**Category:** Ignition\
**Created:** [July 14, 2022, 9:01pm UTC](https://forum.inductiveautomation.com/t/report-sql-data-source-postgres-db-cannot-run-query-with-parameters/61923 "2022-07-14T21:01:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattn1](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mattn1](https://forum.inductiveautomation.com/u/mattn1)\
**Post date:** [July 14, 2022, 9:01pm UTC](https://forum.inductiveautomation.com/t/report-sql-data-source-postgres-db-cannot-run-query-with-parameters/61923/1 "2022-07-14T21:01:55Z")

</div>

I believe the factor against me is how syntax in psql seems to want to work.

Working query in database query browser:  
`SELECT sum("InfluentMGD") as "Influent MGD" FROM hourlytotalization where t_stamp between '2022-7-14 09:00:00'::timestamp and '2022-7-15 00:00:00'::timestamp`

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

Date formatting for datetime strings in reports.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/391f5d57475c6fa337ad2e10909b4b394044cbf3.png)

my sql select query in the datasource for the report. That doesn't run.

`SELECT sum("InfluentMGD") as "Influent MGD" FROM hourlytotalization where t_stamp between '{StartDateString}'::timestamp and '{EndDateString}'::timestamp`

error I am given. From the error it looks like it is having an issue casting the string date as a timestamp datatype.

> WARN: An error occurred while executing Query SELECT sum("InfluentMGD") as "Influent MGD" FROM hourlytotalization where t\_stamp between '{StartDateString}'::timestamp and '{EndDateString}'::timestamp -- ERROR: invalid input syntax for type timestamp: "{StartDateString}" Position: 92

Directions from the manual that tell you how to reference string parameters.  
my sql select query in the datasource for the report. That doesn't run.

currently trying to right the entire sql query as a string parameter hoping I can drop it on the sql datasource...

\*\* UPDATE

so I just wrote the query as a parameter string:  
`"SELECT sum(\"InfluentMGD\") as \"Influent MGD\" FROM hourlytotalization where t_stamp between '"+ dateFormat({StartDate},"yyyy-MM-dd HH:mm:ss")+"'::timestamp and '"+dateFormat({EndDate},"yyyy-MM-dd HH:mm:ss")+"'::timestamp ;"`

and put it into a basic SQL Query like this  
`{TotalizationQuerry}`

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 14, 2022, 9:22pm UTC](https://forum.inductiveautomation.com/t/report-sql-data-source-postgres-db-cannot-run-query-with-parameters/61923/2 "2022-07-14T21:22:53Z")

</div>

Tip: use the \</\> button to format your code properly. Select the code and press the button. (You can edit your post to fix it.) Split the SQL onto multiple lines for ease reading. Proper capitalisation, punctuation and complete sentences helps too.

---

<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 14, 2022, 9:33pm UTC](https://forum.inductiveautomation.com/t/report-sql-data-source-postgres-db-cannot-run-query-with-parameters/61923/3 "2022-07-14T21:33:29Z")

</div>

Java timestamps (java.util.Date) have a standard string conversion that doesn’t match PostgreSQL’s requirements. If you cannot use proper parameters (question marks for substitution) then you must use an intermediate parameter to format the java timestamps in a PostgreSQL-friendly format.

Just say “no” to curly braces in SQL.

---

<div class="post-metadata">

**Author:** ![mattn1](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mattn1](https://forum.inductiveautomation.com/u/mattn1)\
**Post date:** [July 14, 2022, 9:49pm UTC](https://forum.inductiveautomation.com/t/report-sql-data-source-postgres-db-cannot-run-query-with-parameters/61923/4 "2022-07-14T21:49:30Z")

</div>

really appreciate the response.

I see now some of my confusion was because I was improperly calling the parameters.

I had been referencing:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b1a278d3d072f027c1c993d6ed47ba21da3f9d5a.png)

which I see now is not how to do it.
