ARRAYS_TO_OBJECT
functionsupportedCore SQL functionsReturns an OBJECT that contains the keys specified by one input ARRAY and the values specified by another input ARRAY.
Syntax
ARRAYS_TO_OBJECT( <key_array> , <value_array> )
Parameters
| Name | Required | Description |
|---|---|---|
key_array | required | ARRAY of VARCHAR values that specify the keys for the new OBJECT. |
value_array | required | ARRAY of values for the new OBJECT. This ARRAY must be the same length as key_array. The values in this ARRAY should correspond to the keys in key_array. |
Returns
The function returns a value of the type OBJECT. The OBJECT contains the keys and values specified by the input ARRAYs.
Usage notes
- If any element in key_array is not a string, the function reports the following error: 215002 (22000): Key supplied for ARRAYS_TO_OBJECT does not have string type
- key_array and value_array must be equal in length. Otherwise, the function reports the following error: 215001 (22000): Key array and value array had unequal lengths in ARRAYS_TO_OBJECT
- If an element in key_array is NULL, that key and the corresponding value are omitted from the returned OBJECT. If the key is not NULL but the corresponding element in value_array is NULL, the key and NULL value are included in the returned OBJECT.
- The returned OBJECT does not necessarily preserve the original order of the key-value pairs.
- This function doesn’t support a structured type as an input argument.