- Categories:
Semi-structured and structured data functions (Array/Object)
ARRAY_COMPACT¶
Returns a compacted array with missing and null values removed, effectively converting sparse arrays into dense arrays.
Syntax¶
Arguments¶
array1The source array.
Usage notes¶
Semi-structured data (e.g. JSON data) can contain explicit null values, which are distinct from SQL NULLs. A null value in semi-structured data indicates a missing value.
array1should be either an ARRAY data type or a VARIANT data type containing an array value.If the argument is NULL, the result will be NULL.
When you pass a structured array to the function, the function returns a structured array of the same type.
Examples¶
This example shows how to use ARRAY_COMPACT():
Create a simple table and data:
Execute the query: