[英]converting Athena timestamp to date
I am running a query against Athena, and it breaks.我正在对 Athena 进行查询,但它中断了。 Specifically, I get an error for the below fragment:
具体来说,我收到以下片段的错误:
avg(
DATE_DIFF(
'minute',
CAST(from_iso8601_timestamp("sessions_staging".session_start_at) AS TIMESTAMP),
CASE
WHEN CAST("sessions_staging__end_raw" AS TIMESTAMP) + INTERVAL '1' MINUTE > CAST("sessions_staging".next_session_start_at AS TIMESTAMP) THEN CAST("sessions_staging".next_session_start_at AS TIMESTAMP)
ELSE CAST("sessions_staging__end_raw" AS TIMESTAMP) + INTERVAL '30' MINUTE
END
)
) "sessions_staging__average_duration_minutes"
Athena complains with Value cannot be cast to timestamp: 2022-08-03T00:05:54.300Z
.雅典娜抱怨
Value cannot be cast to timestamp: 2022-08-03T00:05:54.300Z
。
I tried a bunch of tricks like casting my date to string then casting again to a time or a timestamp type.我尝试了很多技巧,例如将日期转换为字符串,然后再次转换为时间或时间戳类型。 A similar problem caused by the same issue is covered some in converting to timestamp with time zone failed on Athena
由同一问题引起的类似问题在 Athena 上转换为带时区失败的时间戳时涵盖了一些问题
The value seems to be just fine.价值似乎还不错。 I am able to execute:
SELECT CAST(From_iso8601_timestamp('2022-08-03T00:05:54.300Z') AS timestamp)
.我能够执行:
SELECT CAST(From_iso8601_timestamp('2022-08-03T00:05:54.300Z') AS timestamp)
。 If I do not use CAST()
and just do: "sessions_staging".session_start_at
, it says that (varchar(6), varchar, timestamp) for function date_diff
so I know that session_start_at
is perceived as VARCHAR.如果我不使用
CAST()
并且只使用: "sessions_staging".session_start_at
的(varchar(6), varchar, timestamp) for function date_diff
所以我知道session_start_at
被视为 VARCHAR。 However, for the type of casting described as a solution to my issue to work, in the linked discussion, SELECT
need to be used, it seems.但是,对于被描述为解决我的问题的铸造类型,在链接的讨论中,似乎需要使用
SELECT
。 Everything that I tried including string manipulations did not work.我尝试过的所有操作(包括字符串操作)都不起作用。
How could I re-write my query/casts for Athena to process my request?我如何为 Athena 重新编写查询/强制转换以处理我的请求?
I ended up with:我最终得到:
CAST(DATE_PARSE(my_varchar_date, '%Y-%m-%dT%H:%i:%s.%f%z') AS TIMESTAMP)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.