Flatten out a Record field

Viewed 34

Assume we have a BigQuery table like the following:

enter image description here

Where "Col1" is a Record field. What would be the most efficient way to "flatten out" the table so that part of the Record field becomes columns:

enter image description here

1 Answers

Consider below option

select * from (
  select key, name, value
  from your_table, unnest(col1)
)
pivot (any_value(value) for name in ('A','B','C','D'))        

if applied to sample data as in your question

enter image description here

the output is

enter image description here

Related