AWS Athena:为什么会出现错误“ INVALID_FUNCTION_ARGUMENT:格式无效:“”“?

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

已解决:错误指的是我错过的列中的空值或空值。删除这些行后,查询将起作用。但是,我仍然必须将查询日期转换为日期,仅使用日期作为文字是行不通的。

在 AWS Athena 中,我使用此查询创建了一个视图:

SELECT
    REPLACE(CAST(rt_id AS VARCHAR), '.0', '') AS rt_id,
    survey_id,
    DATE(date_parse(event_date, '%Y-%m-%d')) as survey_date,
    species_name,
    all_runs as count
from
    mt_efishing_data

我正在尝试查询特定日期之间的关系,如下所示:

select *
from counts_dates
where rt_id in ('56','275','276')
and species_name = 'Atlantic salmon'
and survey_date between cast('2023-09-01' as date) and cast('2023-09-30' as date);

但是我收到此错误:

" INVALID_FUNCTION_ARGUMENT: 无效格式:"" "

这就是完整的错误,没有别的了。

这是数据示例:

site_id,event_date,event_date_year,easting,northing,survey_length,survey_area,fished_width,fished_area,survey_method,survey_strategy,n_runs,species_name,run1,run2,run3,all_runs,rt_id,survey_id
1,2023-09-04,2023.0,379176.0,481427.0,37.8,117.18,3.1,117.18,DC ELECTRIC FISHING,SQ,1,Brown / sea trout,4,,,4,275.0,1
1,2023-09-04,2023.0,379176.0,481427.0,37.8,117.18,3.1,117.18,DC ELECTRIC FISHING,SQ,1,Atlantic salmon,0,,,0,275.0,1
1,2023-09-04,2023.0,379176.0,481427.0,37.8,117.18,3.1,117.18,DC ELECTRIC FISHING,SQ,1,Bullhead,2,,,2,275.0,1
2,2023-09-13,2023.0,378596.0,480258.0,55.0,407.0,7.4,407.0,DC ELECTRIC FISHING,SQ,1,Brown / sea trout,1,,,1,255.0,2

如果没有最后一行按日期过滤,查询就可以正常工作。我尝试了不同的语法,包括 date_parse('2023-09-01', '%Y-%m-%d') 并使用 > 和 <. But I don't seem to be able to query the survey_date column in any way.

这可能是由于视图所基于的基础表数据造成的吗?我可以尝试什么?

sql amazon-web-services date amazon-athena between
1个回答
0
投票

您是否尝试过不使用这样的强制转换功能:

select *
from   counts_dates
where  rt_id in ('56','275','276')
       and species_name = 'Atlantic salmon'
       and survey_date between '2023-09-01' and '2023-09-30';

? 另一件事是在视图中使用 CAST 作为 DATE :

CAST(event_date AS DATE) as survey_date,
© www.soinside.com 2019 - 2024. All rights reserved.