1

I have a custom @Query in a repository:

    @Query(value = "select CURRENT_DATE - INTERVAL '?1 days'", nativeQuery = true)
public List<OrderEntity> getOrders(Integer numDays);

I want to add param in '?1 days' for example

getOrders(5) -> select CURRENT_DATE - INTERVAL '5 days'

But it doesn't work, not filter.

How can I write this query so that it works with JPA?

2
  • Try ... - (? || ' days')::interval. Commented Oct 9, 2020 at 12:24
  • Thank you so much, it's a one solution. It works Commented Oct 15, 2020 at 14:57

1 Answer 1

2

Does this work?

select CURRENT_DATE - ?1 * INTERVAL '1 day'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.