Understanding the UNNEST clause in Google’s BigQuery

Krishna Pullakandam
1 min readMar 22, 2023

--

The UNNEST clause in BigQuery is used to flatten an array into a table. The syntax for the UNNEST clause is:

UNNEST(array_name)

where `array_name` is the name of the array that you want to flatten.

For example, if you have an array called `my_array` that contains the following data:

['a', 'b', 'c']

you could use the UNNEST clause to flatten it into a table with the following rows:

a
b
c

The UNNEST clause can be used to flatten multiple arrays at once. For example, if you have two arrays called `my_array_1` and `my_array_2` that contain the following data:

['a', 'b', 'c']
['d', 'e', 'f']

you could use the UNNEST clause to flatten them into a table with the following rows:

a
b
c
d
e
f

The UNNEST clause can also be used to flatten an array into a table with a specific order. For example, if you have an array called `my_array` that contains the following data:

['a', 'b', 'c']

you could use the UNNEST clause to flatten it into a table with the following rows:

a
b
c

but you could also use the UNNEST clause to flatten it into a table with the following rows:

c
b
a

by using the `ORDER BY` clause.

The UNNEST clause is a powerful tool that can be used to flatten arrays into tables in a variety of ways.

--

--

Krishna Pullakandam
Krishna Pullakandam

Written by Krishna Pullakandam

AI and Coffee enthusiast. I love to write about technology, business, and culture.

No responses yet