[英]AWS Athena error: Value cannot be cast to timestamp
I need to query for records with a timestamp no older than 7 days.我需要查询时间戳不超过 7 天的记录。
What type do I need to cast the timestamp field to remedy the error?我需要什么类型的时间戳字段来纠正错误? Or, is there a more succinct / correct way to build the query?或者,是否有更简洁/正确的方式来构建查询?
Query:询问:
SELECT report_timestamp
FROM my_table
WHERE to_unixtime(CAST(report_timestamp AS timestamp)) >= to_unixtime(CAST(now() - interval '7' day AS timestamp))
Error:错误:
Value cannot be cast to timestamp: 1659612600
Thank you.谢谢你。
This should work:这应该有效:
SELECT report_timestamp
FROM my_table
WHERE from_unixtime(CAST(report_timestamp AS bigint)) >= date_add('day', -7, now());
Change CAST(report_timestamp AS timestamp)
to from_unixtime
:将CAST(report_timestamp AS timestamp)
更改为from_unixtime
:
select from_unixtime(1659612600);
Or to from_unixtime(cast(report_timestamp as integer))
(since you mentioned in the comments that report_timestamp
is varchar):或from_unixtime(cast(report_timestamp as integer))
(因为您在评论中提到report_timestamp
是 varchar):
select from_unixtime(cast('1659612600' as integer));
Output: Output:
_col0 _col0 |
---|
2022-08-04 11:30:00.000 UTC 2022-08-04 11:30:00.000 UTC |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.