Snowflake SPLIT_PART 函数不返回 Null 值
Snowflake SPLIT_PART Function not returning Null values
下面是 JSON 文件中的示例数据
'Desktop::abc:voip::GET STARTED' 作为 Col1
当我 运行 Snowflake 中的以下查询时,second_value 的值显示为空白而不是 NULL 值。我如何获得此示例数据的 NULL 值
select 'Desktop::abc:voip::GET STARTED' as Col1
split_part(:Col1 :: String, ':', 1) as First_Value,
split_part(:Col1 :: String, ':', 2) as Second_Value,
split_part(:Col1 :: String, ':', 3) as Third_Value,
split_part(:Col1 :: String, ':', 4) as Fourth_Value;
输出如下
您可以使用 NULLIF() 将零长度字符串强制转换为 NULLS。例如:
select 'Desktop::abc:voip::GET STARTED' as Col1,
NULLiF(split_part(Col1 :: String, ':', 1),'') as First_Value,
NULLiF(split_part(Col1 :: String, ':', 2),'') as Second_Value,
NULLiF(split_part(Col1 :: String, ':', 3),'') as Third_Value,
NULLiF(split_part(Col1 :: String, ':', 4),'') as Fourth_Value
下面是 JSON 文件中的示例数据
'Desktop::abc:voip::GET STARTED' 作为 Col1
当我 运行 Snowflake 中的以下查询时,second_value 的值显示为空白而不是 NULL 值。我如何获得此示例数据的 NULL 值
select 'Desktop::abc:voip::GET STARTED' as Col1
split_part(:Col1 :: String, ':', 1) as First_Value,
split_part(:Col1 :: String, ':', 2) as Second_Value,
split_part(:Col1 :: String, ':', 3) as Third_Value,
split_part(:Col1 :: String, ':', 4) as Fourth_Value;
输出如下
您可以使用 NULLIF() 将零长度字符串强制转换为 NULLS。例如:
select 'Desktop::abc:voip::GET STARTED' as Col1,
NULLiF(split_part(Col1 :: String, ':', 1),'') as First_Value,
NULLiF(split_part(Col1 :: String, ':', 2),'') as Second_Value,
NULLiF(split_part(Col1 :: String, ':', 3),'') as Third_Value,
NULLiF(split_part(Col1 :: String, ':', 4),'') as Fourth_Value