繁体   English   中英

使用 amazon athena at_timezone function sql/presto 的 MST 格式无效

[英]invalid format MST using amazon athena at_timezone function sql/presto

所以我有这样的原始 where 子句:

 --date_parse(coalesce(nullif(cc.timemodified         , ''),nullif(cc.timecreated         , ''), '2500-01-01 15:01:01    '),'%Y-%m-%d %H:%i:%s')         >= date_add('hour', -36, date_parse('2022-11-07 14:08:22','%Y-%m-%d %H:%i:%s'))

我想使用 Athena at_timezone function 将其转换为更多增量,到目前为止我有以下内容:

at_timezone(parse_datetime(coalesce(nullif(cc.timemodified || 'MST', ''),nullif(cc.timecreated || 'MST', ''), '2022-11-01 22:25:32 MST'),'YYYY-MM-dd HH:mm:ss z'), 'US/Mountain') >= parse_datetime('2022-11-01 22:25:32 EST', 'YYYY-MM-dd HH:mm:ss z')
              --date_parse(coalesce(nullif(cc.timemodified         , ''),nullif(cc.timecreated         , ''), '2500-01-01 15:01:01    '),'%Y-%m-%d %H:%i:%s')         >= date_add('hour', -36, date_parse('2022-11-07 14:08:22','%Y-%m-%d %H:%i:%s'))

但这不起作用并产生错误:

INVALID_FUNCTION_ARGUMENT: Invalid format: "MST"
This query ran against the "some data" database, unless qualified by the query. Please post the error message on our forum  or contact customer support  with Query Id:

我在哪里搞砸了?

您的格式 ('YYYY-MM-dd HH:mm:ss z') 适合我:

select parse_datetime('2022-11-01 22:25:32 MST','YYYY-MM-dd HH:mm:ss z');

Output:

_col0
2022-11-01 22:25:32.000 美国/丹佛

看起来你的 concat 中缺少空间,尝试添加它 - cc.timemodified || 'MST' cc.timemodified || 'MST' -> cc.timemodified || ' MST' cc.timemodified || ' MST'

更新程序

您还需要修复nullif处理 - 在coalesce调用之外移动与MST的连接(并将其从nullif中删除) - coalesce(nullif(field, ''), nullif(...),..) || 'MST' coalesce(nullif(field, ''), nullif(...),..) || 'MST'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM