我正在尝试使用Snowflake中的横向函数在Snowflake中解析以下嵌套的JSON,但是我希望“ GoalTime”中的每个嵌套列都显示为一列。例如,>
GoalTime_InDoorOpen 2020-03-26T12:58:00-04:00 GoalTime_InLastOff null GoalTime_OutStartBoarding 2020-03-27T14:00:00-04:00
"GoalTime": [ { "GoalName": "GoalTime_InDoorOpen", "GoalTime": "2020-03-26T12:58:00-04:00" }, { "GoalName": "GoalTime_InLastOff" }, { "GoalName": "GoalTime_InReadyToTow" }, { "GoalName": "GoalTime_OutTowAtGate" }, { "GoalName": "GoalTime_OutStartBoarding", "GoalTime": "2020-03-27T14:00:00-04:00" },
我正在尝试使用Snowflake中的横向函数在Snowflake中解析以下嵌套的JSON,但是我希望“ GoalTime”中的每个嵌套列都显示为一列。例如,...
或者如果您有很多行(看起来像是排期),因此您需要为每个排期添加此代码列,就是您想要的代码
create or replace function JSON_STRING()
returns string
language javascript
as
$$
return `
[
{
"GoalName": "GoalTime_InDoorOpen",
"GoalTime": "2020-03-26T12:58:00-04:00"
},
{
"GoalName": "GoalTime_InLastOff"
},
{
"GoalName": "GoalTime_InReadyToTow"
},
{
"GoalName": "GoalTime_OutTowAtGate"
},
{
"GoalName": "GoalTime_OutStartBoarding",
"GoalTime": "2020-03-27T14:00:00-04:00"
}
]
`;
$$;
select value:GoalName::string as GoalName, value:GoalTime::timestamp as GoalTime
from lateral flatten(input => parse_json(JSON_STRING()));
-- See how the lateral flatten combination works on a JSON variant:
select * from lateral flatten(input => parse_json(JSON_STRING()));