SELECT
to_char(messages. TIME, 'YYYY/MM/DD') AS FullDate,
to_char(messages. TIME, 'MM/DD') AS PartialDate,
COUNT(CASE WHEN message_definitions.error_category = ? THEN 1 END) AS Errors,
error_categories.threshold,
COUNT(CASE WHEN messages.message_id = 14 THEN 1 END) AS Picks
FROM
messages LEFT JOIN
message_definitions USING (message_id) LEFT JOIN
error_categories USING (error_category)
WHERE
(messages. TIME > TIMESTAMP ? - '30 day'::INTERVAL) AND
(messages. TIME < TIMESTAMP '2016-08-03' + '1 day'::INTERVAL) AND
(messages.system_id = ?) AND
(messages.message_id = 14 OR
message_definitions.error_category = ?)
GROUP BY
FullDate, PartialDate, error_categories.threshold
ORDER BY
FullDate DESC LIMIT 40
In the above query, In the where clause, (the first line: (messages. TIME > TIMESTAMP ? - '30 day'::INTERVAL) AND ) when parameter is typecasted (i.e when I put TIMESTAMP before ?) I get the following error
Which is not true for the text data in the second line (messages. TIME < TIMESTAMP '2016-08-03' + '1 day'::INTERVAL) AND
When I change the clause to ( messages. TIME > ? ::TIMESTAMP - '30 day'::INTERVAL) AND ) ( i.e I put the TIMESTAMP after ? ) Can anybody throw some light on what is happening? Thanks!!
Note: PostGresVersion - 9.6 OdBC driver - 32 bit driver (located at C:\Program Files (x86)\psqlODBC\0905\bin\psqlodbc30a.dll.) Same is true with Postgres 8.4 as well.
