问题描述
该语法允许将时间戳转换为各种日期部分,包括unix时代。如下所示(至少在最新的PostgreSQL中):
There's syntax that allows transforming a Timestamp into various date parts, including the unix epoch. This works as follows (in lastest PostgreSQL at least):
SELECT EXTRACT(EPOCH FROM "ts") FROM...
但是,jOOQ似乎不支持此语法,如我发现了,它链接到仍然打开的在jOOQ github上。
However, jOOQ doesn't seem to support this syntax, as evidenced by this discussion I found, which links to the still open Issue #2132 on the jOOQ github.
什么有解决方法吗?我该如何在jOOQ的语法中模拟这种行为(即不必用纯SQL编写整个查询)?
What workarounds are there for this? How can I emulate this behavior within jOOQ's syntax (i.e. without having to write the entire query in pure SQL)?
推荐答案
jOOQ 3.10及以下版本
您始终可以诉诸:
public static Field<Integer> extractEpochFrom(Field<Timestamp> field) {
return DSL.field("extract(epoch from {0})", Integer.class, field);
}
jOOQ 3.11及更高版本中的支持
目前(jOOQ 3.11)对其他非标准 DatePart
类型的实验性支持,例如。
Support in jOOQ 3.11 and more
There is currently (jOOQ 3.11) experimental support for additional, non standard DatePart
types, such as DatePart.EPOCH
. It might work already with PostgreSQL, but not with other databases.
此支持在以后的版本(包括jOOQ 3.12)中将得到改进,请参见:
This support will be improved in future versions, including jOOQ 3.12, see: https://github.com/jOOQ/jOOQ/issues/7794
这篇关于jOOQ“ EXTRACT(EPOCH FROM [field])”解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!