Lateral flatten into columns Snowflake

65 Views Asked by At

I have json like this

"sales_attributes":[
{
    "id":"100000",
    "name":"Colour",
    "value_id":"77777",
    "value_name":"Red Velvet"
},
{
    "id":"100089",
    "name":"Specification",
    "value_id":"88888",
    "value_name":"Bundle"
}]

and I want to make every attributes(name and value_name) become a column like this

variant_field1 variant_value1 variant_field2 variant_value2
Colour Red Velvet Specification Bundle

I have tried with this query

SELECT 
sa.value:name::string as variant_field1,
sa.value:value_name::string as variant_value1,
FROM 
table,
LATERAN FLATTEN(input => sales_attributes) as sa

but the result like this

variant_field1 variant_value1
Colour Red Velvet
Specification Bundle

In this case I want the column created dynamically depend on count of dictionary

Thank you.

0

There are 0 best solutions below