我有许多外部表位于 S3 中的 csv 文件上。我在数字列中有字符串值,应将其解析为空,例如'娜'。当我使用文件格式查询阶段时,这按预期工作。但是,在外部表中使用时出现错误“无法将变体值“na”修改为固定。任何人都能够帮助我理解为什么会出现这种情况?
create or replace file format csv_format
type = csv
field_delimiter = '||'
skip_header=1
encoding='ISO-8859-15'
null_if = 'na'
field_optionally_enclosed_by = '"'
create or replace external table ext_tbl(
col1 data as (value:c1::date)
,col2 number(18,2) as (value:c2::number(18,2)
)
location=@stage
file_format = 'csv_format';
我的表有 100 列,所以我不想在列定义中使用 nullif。
不要尝试依赖可能不适用于
NULL_IF
数据类型的 NUMBER
选项,替代方案是使用 TRY_CAST
显式转换:
create or replace external table ext_tbl(
col1 data as (value:c1::date)
,col2 number(18,2) as (TRY_CAST(value:c2::TEXT AS number(18,2))
)
location=@stage
file_format = 'csv_format';