当我在PgAdmin4或psql中运行以下查询时,我会得到current_time
、now()
和current_timestamp
的相同值:
SELECT now(), CURRENT_TIME, CURRENT_TIMESTAMP;
now | current_time | current_timestamp
-------------------------------+--------------------+-------------------------------
2020-04-27 11:54:55.443006+01 | 11:54:55.443006+01 | 2020-04-27 11:54:55.443006+01
但是,当我使用JDBC驱动程序连接到同一个PostgreSQL数据库,从DBeaver中运行相同的查询时,current_time
和now()
(以及current_timestamp
(之间存在差异:
now |current_time|current_timestamp |
-------------------|------------|-------------------|
2020-04-27 12:57:00| 11:57:00|2020-04-27 12:57:00|
显然,JDBC驱动程序在某种程度上造成了current_time
和current_timestamp
之间的差异。
我的问题:
- 这是JDBC驱动程序的预期行为吗?(为什么?(
- 有没有一种方法可以通过JDBC驱动程序本身的一些配置来控制这种行为,而无需修改依赖JDBC驱动程序的应用程序和查询
current_time
是JDBC不支持的time WITH time zone
。
应用程序需要采取特殊步骤来正确检索该值。所以,是的,这是意料之中的事。我猜DBEaver使用getTime()
,它将时间返回为UTC
这也是不鼓励使用current_time
的原因之一