5

enter image description here

I am trying to flatten inside_array or sub array of nested array data into table rows. I am able to flatten array_data which is outside array. Anybody have any suggestion.Thanks in advance

2 Answers 2

5
#standardSQL
SELECT ... 
FROM `project.dataset.table`,
UNNEST(array_data) AS array_data_rec,
UNNEST(array_data_rec.inside_array) AS inside_array_rec   

To handle "no data inside the inside_array" - use LEFT JOIN instead as in below example

#standardSQL
SELECT ... 
FROM `project.dataset.table`,
UNNEST(array_data) AS array_data_rec
LEFT JOIN UNNEST(array_data_rec.inside_array) AS inside_array_rec   
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks this is helpful.Does it return no data if the there is no data in inside_array_rec and I try to fetch all column from table.
see addition in my answer
Thank you so much. exactly I was looking for.
0

You can do following

...
FROM
   AA.nested_array,
   UNNEST(array_data) as array_data,
   UNNEST(array_data.inside_array) as array_data_inside_array

1 Comment

Thanks.This is helpful.

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.