如何将 sql 中的时间戳转换为 int (vertica)

how to convert a timestamp to int in sql (vertica)

我有一个时间戳 2017-07-19 11:45:01,我希望将其转换为整数。

查询:

select cast(max(event_timestamp) as INT) from error_messages where error_level='ERROR' and user_name='git'

错误:

SQL Error [2366] [42846]: [Vertica][VJDBC](2366) ERROR: Cannot cast type timestamptz to int
  [Vertica][VJDBC](2366) ERROR: Cannot cast type timestamptz to int
    com.vertica.util.ServerException: [Vertica][VJDBC](2366) ERROR: Cannot cast type timestamptz to int

如果您想获取该日期的 Unix 时间戳作为 int 而不是搜索它。 一种选择是以秒为单位计算从您的日期到“1970-01-01”的范围。这是 Unix 时间戳。

使用Vertica中的JULIAN_DAY函数将时间戳转换为整数值或数字。

有关详细信息,请参阅 Vertica 文档 link:https://my.vertica.com/docs/6.1.x/HTML/index.htm#16070.htm

以 1 秒为间隔从日期时间提取数字。

SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-08'); 

你必须这样使用TIMESTAMPDIFF()

SELECT TIMESTAMPDIFF(SECOND,'001-01-01 00:00:00', '2015-02-23 03:12:35');
 timestampdiff 
---------------
   63560257955

得到你想要的时间单位的数量(上面的秒数)因为你想要的时间戳...