SELECT sales_invoice_date,
MONTH( DATE_TRUNC('month',
CASE
WHEN TRIM(sales_invoice_date) = '' THEN
DATE('1999-12-31')
ELSE
DATE_PARSE(sales_invoice_date, '%m/%d/%Y')
END) ) AS DT
FROM testdata_parquet
我使用上面的查询将字符串转换为日期,并能够在 AWS athena 上获取月份编号,但无法获取相应的月份名称
我已经尝试过了monthname
and datename('month', ...)
但他们分别给出了以下错误信息:
SYNTAX_ERROR:第 2:1 行:函数月份名称未注册
SYNTAX_ERROR:第 2:1 行:函数datename未注册
Athena 目前基于 Presto .172,因此您应该参考https://trino.io/docs/0.172/functions/datetime.html https://trino.io/docs/0.172/functions/datetime.html有关日期/时间值的可用函数。
您可以使用以下方式获取月份名称date_format() https://trino.io/docs/0.172/functions/datetime.html#date_format:
date_format(value, '%M')
或类似地format_datetime() https://trino.io/docs/0.172/functions/datetime.html#format_datetime.
format_datetime(value, 'MMM')
Example:
presto:default> SELECT date_format(current_date, '%M');
_col0
----------
December
(1 row)
(已在 Presto 327 上验证,但也适用于 Athena)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)