Not converting yearweek function with QueryDSL

烈酒焚心 提交于 2020-01-07 08:35:13

问题


I would like to use the yearweek() function of QueryDSL, which is supported by QueryDSL. This function generates the query select year(table1.timestamp)*100 + week(table1.timestamp) as col_0_0_ [...]. This does, however, not return a correct result on year endings. I've already opened a bug report for this issue.

I would rather use the built-in SQL yearweek() function, which is directly supported by e.g. MariaDB. Is there a way of using the SQL function YEARWEEK(timestamp) with QueryDSL? Or is it possible to use a custom SQL function with QueryDSL, e.g. given as a String?


Here is an example on how the two implementations return different results on year endings:

SELECT YEARWEEK("2018-01-01");
→ returns 201753, correct

SELECT YEAR("2018-01-01") * 100 + WEEK("2018-01-01")
→ returns 201800, incorrect

回答1:


I found the answer to the question in this StackOverflow answer. You can use a template for this problem.

I used the following template to create a number expression with the SQL yearweek function:

Expressions.numberTemplate(Integer.class, "yearweek({0}, 3)", table1.timestamp);


来源:https://stackoverflow.com/questions/50676538/not-converting-yearweek-function-with-querydsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!