jOOQ“ EXTRACT(EPOCH FROM [field])”解决方法? [英] jOOQ "EXTRACT(EPOCH FROM [field])" workaround?

查看:529
本文介绍了jOOQ“ EXTRACT(EPOCH FROM [field])”解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该语法允许将时间戳转换为各种日期部分,包括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似乎不支持此语法,如此讨论我发现了,它链接到仍然打开的问题#2132 在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及以下版本



您始终可以诉诸使用jOOQ的普通SQL

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 类型的实验性支持,例如 DatePart.EPOCH

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)中将得到改进,请参见:> https://github.com/jOOQ/jOOQ/issues/7794

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])”解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆