Reputation: 185
I would like to convert the below table into a map with multiple key/value pairs
label_a | label_b |
---|---|
1 | 2 |
3 | 4 |
5 | 6 |
into
{'label_a' -> 1, 'label_b' -> 2}
{'label_a' -> 3, 'label_b' -> 4}
{'label_a' -> 5, 'label_b' -> 6}
What would be the easiest way to do this?
All the results I've found are scala/non-presto solutions and I'm not sure how it translates
Upvotes: 0
Views: 1498
Reputation: 5316
You can construct a map with map_from_entries
:
WITH data(label_a, label_b) AS (
VALUES (1, 2), (3, 4), (5, 6)
)
SELECT map_from_entries(array[('label_a', label_a), ('label_b', label_b)])
FROM data
Upvotes: 1