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
| Function | What it does |
|---|---|
| ARRAY | ARRAY(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_CONCAT | ARRAY_CONCAT(arr1, arr2, ...) joins two or more arrays of the same element type into one, keeping order and duplicates. |
| ARRAY_FIRST | ARRAY_FIRST(arr) returns the first element of an array, typed as the array's elements. |
| ARRAY_LAST | ARRAY_LAST(arr) returns the last element of an array without the ARRAY_LENGTH(arr) - 1 arithmetic. |
| ARRAY_LENGTH | ARRAY_LENGTH(arr) returns the number of elements in an array as INT64: 0 for an empty array and NULL for a NULL array. |
| ARRAY_REVERSE | ARRAY_REVERSE(arr) returns the same array with its elements in the opposite order. |
| ARRAY_SLICE | ARRAY_SLICE(arr, start_offset, end_offset) returns the elements between two zero-based offsets, both ends included. |
| ARRAY_TO_STRING | ARRAY_TO_STRING(arr, delimiter[, null_text]) joins the elements of a STRING or BYTES array into one string. |
| GENERATE_ARRAY | GENERATE_ARRAY(start, end[, step]) returns an array of numbers from start to end, both inclusive, stepping by 1 or by step. |
| OFFSET and SAFE_OFFSET | arr[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. |
| UNNEST | UNNEST turns an array into a table with one row per element. |
More of the BigQuery reference
Date functionsDatetime functionsTimestamp functionsString functionsAggregate functionsWindow functionsJSON functionsConversion functionsConditional expressionsMathematical functionsHash and utility functionsQuery syntaxDDL statementsDML statementsScripting and data movementINFORMATION_SCHEMAError messagesBigQuery pricingPricing calculator
