title: Postgres: Error [42601] Error: Syntax error at or near "$2". Error while executing the Query
body: <pre><code>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 &gt; TIMESTAMP ? - '30 day'::INTERVAL) AND 
      (messages. TIME &lt; 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
  </code></pre>
  
  <p>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</p>
  
  <p><a href="https://i.stack.imgur.com/r60x4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r60x4.jpg" alt="enter image description here"></a></p>
  
  <p>Which is not true for the text data in the second line   (messages. TIME &lt; <strong>TIMESTAMP</strong>  '2016-08-03' + '1 day'::INTERVAL) AND</p>
  
  <p>When I change the clause to ( messages. TIME > <strong>? ::TIMESTAMP</strong> - '30 day'::INTERVAL) AND 
  ) 
  ( i.e I put the TIMESTAMP after ? )
  Can anybody throw some light on what is happening?  Thanks!!</p>
  
  <p>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.</p>