📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

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 | +-----------------------------------------+

Was this page helpful?