title: Postgres Interval Spring Data Dynamic Parameter not working
body: <p>I need to pass in a dynamic param to a Spring Data Postgres Native Query. The param is in an interval expression.</p>
  
  <p>At the time of running the code, I verify from pgAdmin that the following returns <strong>1 result only (correctly):</strong></p>
  
  <p><code>select * from recalls_t where created_date &lt;=  (now() - interval '18 hour')</code></p>
  
  <p><strong>PROBLEM:</strong></p>
  
  <p>1) In the Spring Data code, the following <code>?1</code> notation returns <strong>2 results incorrectly</strong>:</p>
  
  <pre><code>@Query(value="select * from recalls_t where created_date &lt;=  (now() - interval '?1 hour')", 
         nativeQuery=true)
  public List&lt;RecallsT&gt; findActiveRecallsInLastHrs(@Param("hours") int hours);
  </code></pre>
  
  <p>2) Then I tried the solution in this thread: <a href="https://stackoverflow.com/questions/43767284/postgres-interval-not-working-with-native-spring-data-jpa-query">Postgres Interval not working with native spring data JPA query</a></p>
  
  <p>They said to use a multiple of a single-unit interval. But this also returns <strong>2 results incorrectly</strong>:</p>
  
  <pre><code>@Query(value="select * from recalls_t where created_date &lt;=  (now() - 
         (interval '1 hour') * :hours)", 
         nativeQuery=true)
  public List&lt;RecallsT&gt; findActiveRecallsInLastHrs(@Param("hours") int hours);
  </code></pre>
  
  <p>The only way I found to fix this is to hard-code the number "18" in my Spring Data query. So now there's no dynamic param, and I get 1 result correctly. None of the Dynamic Param implementations work.</p>