1

Let's say I have a column containing data in this format inside a table named myTable:

myColumn
[{"id": 1, color: "red"}, {"id": 2, color: "blue"}]
[{"id": 1, color: "orange"}, {"id": 2, color: "purple"}]

How do I get extract the colors into an array for each row, in this format?

result
[red, blue]
[orange, purple]

What I have tried so far -

select arr.color
from myTable as mt
    lateral view outer explode(mt.myColumn) as arr
limit 10;

Unfortunately this produces result containing 1 color in each row. How do I create an array for colors in each row?

1 Answer 1

3

You don't need to use explode function. You can merely call your desired field directly on your array column:

SELECT myColumn.color FROM myTable
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.