I have a problem to map PostgreSQL expression below, that extracts hours/minutes/dow, to a CriteriaBuilder expression:
select extract(hour from start_time) from meetings where id = 5;
meetings
have start_time
field in a database that maps into ZonedDateTime start
Java entity field later. I have tried CriteriaBuilder.function()
, but I can not realy understand how to map hour from start_time
expression as one function parameter.
Thanks for a help!
2
Answers
I have used
DATE_PART
function to fetch hours count instead:SQL-request looks similar:
Extract/Date_Part will give only the specified subfield from the timestamp (I assume
ZonedDateTime
maps to the Postgres data typetimestamp with time zone
). If you want the full time (hh:mi:ss) then rather that anextract
for each you just cast the column totime
. SoIf you do not want seconds then use to_char: