不使用QueryDSL转换年周功能 [英] Not converting yearweek function with QueryDSL
问题描述
我想使用QueryDSL的yearweek()
功能,该功能由QueryDSL支持.此函数生成查询select year(table1.timestamp)*100 + week(table1.timestamp) as col_0_0_ [...]
.但是,这不会在年末返回正确的结果.我已经为此问题打开了错误报告.
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.
我宁愿使用内置的SQL yearweek()
函数,该函数直接由例如MariaDB.是否可以将SQL函数YEARWEEK(timestamp)
与QueryDSL一起使用?或者是否可以将自定义SQL函数与QueryDSL一起使用,例如以字符串形式给出?
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
推荐答案
我在此 StackOverflow答案中找到了问题的答案一个>.您可以使用模板解决此问题.
I found the answer to the question in this StackOverflow answer. You can use a template for this problem.
我使用以下模板通过SQL yearweek函数创建数字表达式:
I used the following template to create a number expression with the SQL yearweek function:
Expressions.numberTemplate(Integer.class, "yearweek({0}, 3)", table1.timestamp);
这篇关于不使用QueryDSL转换年周功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!