0

I have a query like so:

@Query(nativeQuery = true, value = "" +
      "SELECT f.name AS name " +
      "FROM foo f " +
      "WHERE f.date > current_date - INTERVAL :days DAY")
Optional<Object> foo(Integer days);

The problem is that :days requires single quotes around it.

When I try doing something like this

"WHERE f.date > current_date - INTERVAL '" + ":days" + "' DAY"

or this

"WHERE f.date > current_date - INTERVAL ':days' DAY"

the :days placeholder does not get escaped.

I am using a Postgres database. Does anyone have a solution to this?

Any help is much appreciated!

DGrinbergs
  • 27
  • 1
  • 5

1 Answers1

0

I found the solution. I just needed to do the following

"WHERE f.date > current_date - :days * INTERVAL '1' DAY"

Thanks to this solution

DGrinbergs
  • 27
  • 1
  • 5