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

时间:2017-07-19 15:49:51

标签: sql vertica

我的时间戳为2017-07-19 11:45:01,我希望它转换为int。

查询:

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

3 个答案:

答案 0 :(得分:3)

您必须以这种方式使用override fun onDataChange(p0: DataSnapshot?) { if(p0 != null) { val food = p0.getValue(FBFood::class.java)!! val repo = LocalFoodRepository() doAsync { repo.insertFood(this@LoginActivity, Food(food.foodId, food.foodName, food.foodDesc)) repo.insertServingDetails(this@LoginActivity, food.servingList.map { it.component2() }) repo.saveFood(this@LoginActivity, personalizedFood) it.onNext(true) it.onCompleted() } } else { it.onNext(false) it.onCompleted() } }

TIMESTAMPDIFF()

从你想要的时间戳开始,得到你想要的时间单位数(上面的SECOND)......

答案 1 :(得分:1)

如果你想把那个日期的Unix时间戳作为int而不是搜索堡垒。 一种选择是计算从您的日期到' 1970-01-01'以秒为单位。这是Unix时间戳。

答案 2 :(得分:0)

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

有关详细信息,请参阅Vertica文档链接: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'); 
相关问题