Request a demo

BigQuery reference

BigQuery array functions

ARRAY is a first-class type in BigQuery: nested and repeated fields are how BigQuery avoids joins. These functions build arrays, read elements, flatten them with UNNEST and turn them back into strings.

Functions in this category

FunctionWhat it does
ARRAYARRAY(subquery) collects the rows a subquery returns into an array, one element per row, and returns an empty array (never NULL) when there are no rows.
ARRAY_CONCATARRAY_CONCAT(arr1, arr2, ...) joins two or more arrays of the same element type into one, keeping order and duplicates.
ARRAY_FIRSTARRAY_FIRST(arr) returns the first element of an array, typed as the array's elements.
ARRAY_LASTARRAY_LAST(arr) returns the last element of an array without the ARRAY_LENGTH(arr) - 1 arithmetic.
ARRAY_LENGTHARRAY_LENGTH(arr) returns the number of elements in an array as INT64: 0 for an empty array and NULL for a NULL array.
ARRAY_REVERSEARRAY_REVERSE(arr) returns the same array with its elements in the opposite order.
ARRAY_SLICEARRAY_SLICE(arr, start_offset, end_offset) returns the elements between two zero-based offsets, both ends included.
ARRAY_TO_STRINGARRAY_TO_STRING(arr, delimiter[, null_text]) joins the elements of a STRING or BYTES array into one string.
GENERATE_ARRAYGENERATE_ARRAY(start, end[, step]) returns an array of numbers from start to end, both inclusive, stepping by 1 or by step.
OFFSET and SAFE_OFFSETarr[OFFSET(n)] returns the array element at zero-based position n and fails if n is out of range; arr[SAFE_OFFSET(n)] returns NULL instead.
UNNESTUNNEST turns an array into a table with one row per element.

More of the BigQuery reference

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.