- Categories:
Semi-structured and structured data functions (Array/Object)
ARRAYS_TO_OBJECT¶
Returns an OBJECT that contains the keys specified by one input ARRAY and the values specified by another input ARRAY.
Syntax¶
Arguments¶
key_arrayARRAY of VARCHAR values that specify the keys for the new OBJECT.
value_arrayARRAY 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 inkey_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_arrayis not a string, the function reports the following error:key_arrayandvalue_arraymust be equal in length. Otherwise, the function reports the following error:If an element in
key_arrayis 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_arrayis 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.
Examples¶
The following example returns an OBJECT that contains key-value pairs specified by two input ARRAYs:
In the following example, the ARRAY of keys includes a NULL value. That key and the corresponding value are omitted from the returned OBJECT.
In the following example, the ARRAY of values includes a NULL value. That value and the corresponding key are included in the returned OBJECT.