您的位置:首页 > 数据库

SQL DATE_FORMAT in Alternative in Jooq

2018-03-01 18:36 169 查看
I’m using 3.5 jooq version

I know that jooq don’t support DATE_FORMAT function but what are the alternatives

This is the query that i want to create with JOOQ

SELECT DATE_FORMAT(`date_create`, '%d/%m/%Y') AS date_create FROM users
GROUP BY DATE_FORMAT(`date_create`, '%d/%m/%Y')


Whenever you need a vendor-specific SQL feature that is not supported by jOOQ out of the box, the plain SQL API will be your friend. Write a utility as such:

public static Field<String> dateFormat(Field<Date> field, String format) {
return DSL.field("date_format({0}, {1})", SQLDataType.VARCHAR,
field, DSL.inline(format));
}


You can then use it like any other jOOQ-provided function:

DSL.using(configuration)
.select(dateFormat(USERS.DATE_CREATE, "%d/%m/%Y").as("date_create"))
.from(USERS)
.groupBy(dateFormat(USERS.DATE_CREATE, "%d/%m/%Y"))
.fetch();


转载自http://w3cgeek.com/sql-date_format-in-alternative-in-jooq.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: