Skip to main content

AS_ARRAY

Strict casting VARIANT values to ARRAY data type. If the input data type is not VARIANT, the output is NULL. If the type of value in the VARIANT does not match the output value, the output is NULL.

Syntax

AS_ARRAY( <variant> )

Arguments

ArgumentsDescription
<variant>The VARIANT value

Return Type

Variant contains Array

Examples

SELECT as_array(parse_json('[1,2,3]'));
+---------------------------------+
| as_array(parse_json('[1,2,3]')) |
+---------------------------------+
| [1,2,3] |
+---------------------------------+

SELECT as_array(parse_json('["a","b","c"]'));
+---------------------------------------+
| as_array(parse_json('["a","b","c"]')) |
+---------------------------------------+
| ["a","b","c"] |
+---------------------------------------+

-- Returns NULL for non-array values
SELECT as_array(parse_json('{"key":"value"}'));
+-----------------------------------------+
| as_array(parse_json('{"key":"value"}')) |
+-----------------------------------------+
| NULL |
+-----------------------------------------+
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today