Vertica时间戳和夏令时

时间:2016-10-26 23:44:37

标签: sql jdbc timestamp vertica

我在Vertica遇到一个与夏令时有关的奇怪问题。

当查询将时间戳存储为TIMESTAMP(6)WITHOUT TIME ZONE的表时,作为时间戳返回的时间和转换为varchar时返回的时间相互间隔一小时,受夏令时影响的时间时间。时间戳返回距离应该是一小时;将时间戳转换为varchar会产生正确的结果。

示例:

-- query
select time_, time_::varchar
from <table_name>
where time_ = '2016-03-13 02:38:01.914999'

-- result
timestamp:                      converted to varchar:
'2016-03-13 03:38:01.914999'    '2016-03-13 02:38:01.914999'
              |                               |
              |                               |
              v                               v
        this is wrong           this is the desired behavior

为了解决问题,当输出按时间排序时,Vertica会正确处理时间戳:

-- query
select t.time_, t.time_::varchar
from <table_name> t
where t.time_ >= '2016-03-13 00:30:00'
  and t.time_ <  '2016-03-13 04:00:00'
order by t.time_

-- result
timestamp:                   converted to varchar:
'2016-03-13 00:31:25.087'    '2016-03-13 00:31:25.087'  ---> ok
'2016-03-13 00:31:32.236'    '2016-03-13 00:31:32.236'  ---> ok
'2016-03-13 03:38:02.042'    '2016-03-13 02:38:02.042'  ---> do not match
'2016-03-13 03:18:28.332'    '2016-03-13 03:18:28.332'  ---> ok

我使用此Docker镜像(https://hub.docker.com/r/sumitchawla/vertica/)运行Vertica,并通过JDBC驱动程序连接。这个问题与应用程序无关 - 它是在从SQuirreL和MATLAB查询数据时发生的。我还确认Vertica实例的时区设置为UTC:

-- query
show timezone

-- result
name:         setting:
'timezone'    'UTC'

我如何获得所需的行为?为了清楚起见,我希望'select time_'返回'select time _ :: varchar'返回的内容。

谢谢!

更新:基于来自@mauro和@woot的非常有用的反馈,看起来这可能是Vertica JDBC驱动程序版本7.1.2-0的已知错误,并且可能存在修复稍后发布(7.1.2-17;见https://my.vertica.com/docs/ReleaseNotes/7.1.x/HP_Vertica_7.1.x_Release_Notes.htm)。我试图从HP获得此修补程序(它只向企业客户正式提供修补程序),如果成功,将更新此线程。

与此同时,这是一个更简单的查询,它可以更容易地重现问题的核心:

-- query
select
  to_timestamp('2016-03-13 02:38:01', 'yyyy-mm-dd HH:MI:SS'),
  to_timestamp('2016-03-13 02:38:01', 'yyyy-mm-dd HH:MI:SS')::varchar

-- result obtained in VSQL (CORRECT):
'2016-03-13 02:38:01.0'    '2016-03-13 02:38:01'

-- result obtained via JDBC driver release 7.1.2-0 (INCORRECT):
'2016-03-13 03:38:01.0'    '2016-03-13 02:38:01'

0 个答案:

没有答案