如何从“没有时区的时间戳”字段收集到没有时区的Java时间戳

如何从“没有时区的时间戳”字段收集到没有时区的Java时间戳,java,psql,jooq,timezone-offset,Java,Psql,Jooq,Timezone Offset,我的Jooq查询: dslContext.select( timeInterval, ifnull(avg(field(FieldName.AVERAGE, Double.class)) .cast(Double.class), 0.0)) .from(channelTimebucketQuery) .groupBy(ti

我的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类型不带时区或仅时间戳为java.SQL.TIMESTAMP。出于我们都感到遗憾的历史原因,java.sql.Timestamp扩展了java.util.Date,它通过将JVM时区(即TimeZone.getDefault)与unix时间戳相关联来建模没有时区的时间戳

没有时区数据类型的SQL时间戳的更好表示形式是java.TIME.LocalDateTime,jOOQ也支持它。jOOQ的代码生成器的最新版本将设置为true,使JSR-310类型成为默认类型

然而,尽管调试器和java.sql.Timestamp中关联的隐式时区存在混淆,但这两种数据类型彼此等效,可以通过以下方式相互转换:

如果可以在数据库中使用带时区的时间戳,在Java中使用OffsetDateTime,则效果更好。Timestamp类的设计很差,而且很早就过时了。没有时区的时间戳不是时间戳,这意味着它没有定义唯一的时间点。时间戳的实例只是一个时间点,它独立于时区,因此与没有时区的SQL时间戳完全不同,后者是一天中的日期和时间。尽管时间戳通常会在其中保留一个时区,这是非常令人困惑的,但您应该将其视为一个实现细节,这与您无关,可能是一种优化尝试,我不知道。从概念上讲,它没有时区。