CAST(日期字符串)|不工作 | AWS 雅典娜

问题描述 投票:0回答:1

在创建外部表并将“unformattedDate”指定为字符串后,我无法使用函数 CAST(string as date)

这是我的创建表:

CREATE EXTERNAL TABLE IF NOT EXISTS tempTable
(unformattedDate as string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
STORED AS TEXTFILE
LOCATION 's3://...'
TBLPROPERTIES ('skip.header.line.count'='1')

查询:

Select unformattedDate, SPLIT_PART(unformattedDate,' ',1) as "unformattedDate2"

结果:

未格式化日期 未格式化的日期 2
9/9/2022 上午 12:00:00 9/9/2022

这是我尝试转换为日期时失败的查询

Select unformattedDate,
SPLIT_PART(unformattedDate,' ',1) as "unformattedDate2",
CAST(SPLIT_PART(unformattedDate,' ',1) as Date) "unformattedDate3"

错误:

SQL Error [100071] [HY000]: [Simba][AthenaJDBC](100071) An error has been thrown from the AWS Athena client. INVALID_CAST_ARGUMENT: Value cannot be cast to date:  [Execution ID: 80c26833-daac-44e8-8441-3464d9757a6d]
amazon-web-services amazon-athena
1个回答
0
投票

9/9/2022 12:00:00 AM
是一种非标准的日期格式。如果是
2022-09-09
格式,那雅典娜就能看懂了

你需要使用类似的东西:

select date_parse('9/9/2022','%d/%m/%Y') from table

但是,如果它真的只显示一位数字表示日期和月份,即使那样也可能很困难。

请参阅:日期和时间函数和运算符 — Presto 文档

© www.soinside.com 2019 - 2024. All rights reserved.