Search code examples
javapostgresqldatejpqlquerydsl

date_part or EXTRACT function in Querydsl


There a way to use date_part or EXTRACT function or equivalent using querydsl? I'm using spring framework to build a rest aplicaiton with querydsl, and a need to make a group by date interval like

QUARTER of the year (SELECT EXTRACT(QUARTER FROM TIMESTAMP '2001-02-16 20:38:40')

or

SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40')

I have been search for a solution using just querydsl but withou success.

I'm using postgreSQL db.


Solution

  • I notice when i get a month or a year of a DataPath type the extract function is used, so i divide by 3 to get a quarter.

    Like this, to get the secont part of the year:

    query.where(classQ.thedate.month().divide(3).ceil().eq(2))
    

    Anyway, now i know this is a little dumb question rsrsrs,but maybe help someone