我的 Jooq 查询:
dslContext.select(
timeInterval,
ifnull(avg(field(FieldName.AVERAGE, Double.class))
.cast(Double.class), 0.0))
.from(channelTimebucketQuery)
.groupBy(timeInterval)
.orderBy(timeInterval)
.collect(Collectors.toMap(Record2::component1, Record2::component2));
但是我的分析器说它应该返回一个没有时区的时间戳。
select pg_typeof(time_bucket) from (
select "alias_67258973"."time_bucket", coalesce(cast(avg(average) as double precision), 0.0) from (select "public"."time_bucket_gapfill"("bucket_width" := cast("public"."create_interval"("seconds" := 43200) as "pg_catalog"."interval"), "ts" := cast("public"."testTable"."time" as timestamp), "start" := cast(null as timestamp), "finish" := cast(null as timestamp)) as "time_bucket", avg("public"."testTable"."average") as "average" from "testTable" where ("public"."testTable"."device" in ('702088' ) and "public"."testTable"."time" >= timestamp '2020-02-10 13:57:28.2212375' and "public"."testTable"."time" <= timestamp '2020-02-24 13:57:28.2222399') group by time_bucket) as "alias_67258973" group by "alias_67258973"."time_bucket" order by "alias_67258973"."time_bucket"
) as x;
时区从哪里来?如何将时区设置为 + 0000
最佳答案
SQL 类型的默认 JDBC 类型 TIMESTAMP WITHOUT TIME ZONE
(或只是 TIMESTAMP
)是 java.sql.Timestamp
。由于历史原因,我们都感到遗憾,java.sql.Timestamp
延伸java.util.Date
,其模型为 TIMESTAMP WITHOUT TIME ZONE
通过将您的 JVM 时区(即 TimeZone.getDefault()
)与 unix 时间戳相关联。
更好地表示 SQL TIMESTAMP WITHOUT TIME ZONE
数据类型为java.time.LocalDateTime
,jOOQ 也支持。 jOOQ 代码生成器的最新版本将设置 <javaTimeTypes>true</javaTimeTypes>
使 JSR-310 类型成为默认类型。
尽管如此,尽管调试器和 java.sql.Timestamp
中相关的隐式时区造成了困惑。 ,这两种数据类型彼此等效,并且可以通过以下方式相互转换:
关于java - 如何从 "timestamp without time zone"字段收集到没有时区的 Java 时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60378166/