davidleongz
davidleongz

Reputation: 181

JPA Params with nativeQuery in Postgresql

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?

Upvotes: 1

Views: 288

Answers (1)

GMB
GMB

Reputation: 222382

Does this work?

select CURRENT_DATE - ?1 * INTERVAL '1 day'

Upvotes: 2

Related Questions