File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ order_id | coupons_applied
3232444 |
3333444 |
3434
35+ ### Using the TRANSFORM function with a Lamba expression
36+
3537We can using the TRANSFORM function to apply a Lambda Fuction to each element in the JSON array to extract the Coupon as following:
3638
3739``` sql
@@ -50,3 +52,17 @@ FROM orders;
5052| 222 | [ "ccc" ] |
5153| 333 | [ "ccc", "aaa", "eee" ] |
5254| 444 | |
55+
56+ ### Using the Lateral Flatten
57+
58+ The same can be achieved using the Lateral Flatten in Snowflake:
59+
60+ ``` sql
61+
62+ select order_id, listagg (f .value :Coupon, ' , ' )
63+ from orders
64+ , lateral flatten(input => parse_json(orders .coupon_json_array )::variant, OUTER => TRUE) as f
65+ group by all
66+ ```
67+
68+ How this will be a lot slower compare to using the TRANSFORM function.
You can’t perform that action at this time.
0 commit comments