Skip to content

Commit 0f9c8b6

Browse files
Update using-transform-function-in-snowflake-to-extract-values-from-a-json-array.md
1 parent 28bc3eb commit 0f9c8b6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

using-transform-function-in-snowflake-to-extract-values-from-a-json-array.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,22 @@ We can using the TRANSFORM function to apply a Lambda Fuction to each element in
3838

3939
```sql
4040
SELECT
41-
order_id,
42-
TRANSFORM(
41+
order_id
42+
, TRANSFORM(
4343
parse_json(orders.coupon_json_array)::ARRAY,
4444
promo OBJECT -> promo:"Coupon"
45-
) as coupons_applied
45+
) as coupons_applied_array
46+
, ARRAY_TO_STRING(coupons_applied_array, ', ')
4647
FROM orders;
4748
```
4849

49-
| order_id | coupons_applied |
50-
|----------|-------------------------------|
51-
| 111 | [ "bbb", "aaa" ] |
52-
| 222 | [ "ccc" ] |
53-
| 333 | [ "ccc", "aaa", "eee" ] |
54-
| 444 | |
50+
| order_id | coupons_applied_array | coupons_applied |
51+
|----------|-------------------------------|-----------------|
52+
| 111 | [ "bbb", "aaa" ] | bbb, aaa |
53+
| 222 | [ "ccc" ] | ccc |
54+
| 333 | [ "ccc", "aaa", "eee" ] | ccc, aaa, eee |
55+
| 444 | | |
56+
| 444 | | |
5557

5658
### Using the Lateral Flatten
5759

0 commit comments

Comments
 (0)