I need to extract some unit from a date for further use in conditions. I found sql function date_part() and wrote following method:
Expression<Integer> extractUnit(CriteriaBuilder cb, Expression<Timestamp> date, String unit) {
return cb.function("date_part", Integer.class, cb.literal(unit), date);
}
But I recieve
Internal Exception: org.postgresql.util.PSQLException: ERROR: function date_part(character varying, unknown) is not unique
At the beginning I tried argument date as Expression<LocalDate>
, and received this issue. I decided to test if this function actually works. Runned sql script select date_part('month', '2024-04-27')
and received the same exception. Then I changed this select to select date_part('month', timestamp '2024-04-27')
and it works well.
I changed Expression<LocalDate> date
to Expression<Timestamp> date
, but the issue is still here.
How to fix it or maybe there is another way how to extract value of unit using criteria builder?