- Categories:
Conversion functions , Semi-structured and structured data functions (Array/Object)
TO_ARRAY¶
Converts the input expression to an ARRAY value.
Syntax¶
Arguments¶
exprAn expression of any data type.
Returns¶
This function returns a value of type ARRAY or NULL:
If the input is an ARRAY, or a VARIANT containing an ARRAY value, the value is returned unchanged.
If
expris a NULL or JSON null value, the function returns NULL.For any other value, the value returned is a single-element array that contains this value.
Usage notes¶
To create an array that contains more than one element, you can use ARRAY_CONSTRUCT or STRTOK_TO_ARRAY.
Examples¶
Create a table, and insert data by calling the TO_ARRAY function:
Execute a query that shows the single-element arrays created during the insert and the result of calling ARRAY_CAT to concatenate the two arrays:
This example demonstrates that TO_ARRAY converts a string input expression to an array with a single element, even when the input expression includes delimiters (such as commas):
To convert the same string input expression into an array with multiple elements, you can use the STRTOK_TO_ARRAY function: