ARRAYS_ZIP
functionsupportedCore SQL functionsReturns an array of objects, each of which contains key-value pairs for an nth element in the input arrays. For example, in the returned array, the first object contains key-value pairs for each first element in the input arrays, the second object contains key-value pairs for each second element in the input arrays, and so on.
Syntax
ARRAYS_ZIP( <array> [ , <array> ... ] )
Parameters
| Name | Required | Description |
|---|---|---|
array | required | An input array. The input arrays can be of different lengths. If any of the input arrays is a structured array, all input arrays must be structured arrays. |
Returns
Returns a value of one of the following types: - If the input arrays are semi-structured arrays, the function returns a semi-structured array of structured objects. - If the input arrays are structured arrays, the function returns a structured array of structured objects. The definition of the structured object depends on the number of input arrays and the types of values in the arrays. - If any of the input arrays is NULL, the function returns NULL. Each object contains the key-value pairs for the values of an nth element in the input arrays. The key ($1, $2, and so on) represents the position of the input array. For example, suppose that you pass in these arrays: The function returns the following array of objects: In the returned array: - The first object contains the first elements of all input arrays. - The second object contains the second elements of all input arrays. - The third object contains the third elements of all input arrays. The keys in the objects identify the input array: - The $1 key-value pairs contain the values from the first input array. - The $2 key-value pairs contain the values from the second input array. - The $3 key-value pairs contain the values from the third input array.
Usage notes
- The returned array is as long as the longest input array. If some input arrays are shorter, the function uses a JSON null for the remaining elements missing in the shorter arrays.
- If the input array includes a NULL element, the function returns a JSON null for that element.