Problem with prostgresql and SQLExpressions.datetrunc

62 views
Skip to first unread message

Nikita Romashkin

unread,
May 4, 2016, 6:27:44 AM5/4/16
to Querydsl
I am using postgresql and want get aggregation of how much payment by days

Entity
public class Appointment {
    private Double price;
    private DateTime datePayment;
}
DTO
@Data
public class FinanceStatisticDTO implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
   
    private DateTime truncedDate;
   
    private Double total;

    public FinanceStatisticDTO() {
    }
}
Query
query.from(app).where(exp)
    .groupBy(SQLExpressions.datetrunc(DatePart.day, app.datePayment))
    .list(Projections.bean(FinanceStatisticDTO.class,
        SQLExpressions.datetrunc(DatePart.day, app.datePayment).as("truncedDate"), app.price.sum().as("total")));
But generated sql
select trunc_day(appointmen0_.date_payment) as col_0_0_, sum(appointmen0_.price) as col_1_0_ from appointment.appointments appointmen0_ cross join contract.contracts contract1_ where appointmen0_.contract_id=contract1_.id and contract1_.contract_group=? and appointmen0_.date_payment>=? group by trunc_day(appointmen0_.date_payment)
Function trunc_day does not exists in PostgreSQL. For example http://www.postgresql.org/docs/9.5/static/functions-datetime.html

Please help me.

timowest

unread,
May 14, 2016, 3:15:15 AM5/14/16
to Querydsl
Do you use Querydsl SQL or JPA?
Reply all
Reply to author
Forward
0 new messages