I'm trying to cast or convert a timestamp column to an integer value in a Redshift database. I know it is possible in other SQL-based databases and I've done this before, however in Redshift I can't get it to work.
我正在尝试将时间戳列转换或转换为Redshift数据库中的整数值。我知道它可以在其他基于SQL的数据库中使用,之前我已经这样做了,但是在Redshift中我无法使用它。
I've tried some variations of cast
and also convert
(http://docs.aws.amazon.com/redshift/latest/dg/r_CAST_function.html).
我已经尝试了一些演员阵容的变化,也转换了(http://docs.aws.amazon.com/redshift/latest/dg/r_CAST_function.html)。
Here is an example:
这是一个例子:
SELECT cast(finish_time as integer) FROM table;
SELECT cast(finish_time as integer)FROM table;
It gives me the error message:
它给了我错误信息:
SQL Error Invalid operation: cannot cast type timestamp without time zone to integer;
SQL错误无效操作:无法将没有时区的类型时间戳转换为整数;
Is it possible to get a timestamp as an integer?
是否可以将时间戳作为整数?
1 个解决方案
#1
3
try select extract('epoch' from finish_time)
, it will give you Unix ms timestamp
尝试select extract(来自finish_time的'epoch'),它会给你Unix ms时间戳
#1
3
try select extract('epoch' from finish_time)
, it will give you Unix ms timestamp
尝试select extract(来自finish_time的'epoch'),它会给你Unix ms时间戳