【发布时间】:2020-02-24 14:36:45
【问题描述】:
我的 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));
返回一个附有 Timezone 的 Timestamp 和一个 double
但是我的 Profiler 说它应该返回一个没有时区的时间戳。
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
【问题讨论】:
-
如果您可以在数据库中使用
timestamp with time zone并在Java 中使用OffsetDateTime,那就更好了。Timestamp类设计不佳且早已过时。而timestamp without time zone没有时间戳,这意味着它没有定义唯一的时间点。 -
Timestamp的实例只是一个时间点,它与时区无关(因此与没有时区的 SQL 时间戳完全不同,后者是日期和时间)。Timestamp经常在其中保留一个时区,这非常令人困惑,但是您应该将其视为与您无关的实现细节(可能是某种优化的尝试,我不知道)。 概念上没有时区。
标签: java psql jooq timezone-offset