Returns the smallest element in an array.
Syntax
T array_min(array<T> <a>)Parameters
| Parameter | Required | Description |
|---|---|---|
a | Yes | The input array. T specifies the data type of the array elements. |
Supported types for T:
| Category | Types |
|---|---|
| Integer | TINYINT, SMALLINT, INT, BIGINT |
| Floating-point | FLOAT, DOUBLE |
| Boolean | BOOLEAN |
| Decimal | DECIMAL, DECIMALVAL |
| Date and time | DATE, DATETIME, TIMESTAMP, IntervalDayTime, IntervalYearMonth |
| String | STRING, VARCHAR, CHAR |
| Binary | BINARY |
| Complex | ARRAY, STRUCT, MAP |
Return value
Returns the smallest element in array a, with the same data type as the array elements.
| Condition | Return value |
|---|---|
Array a is null | null |
Array a contains null elements | Minimum of the non-null elements; null elements are skipped |
Usage notes
NULL handling: Null elements are skipped during comparison. Only non-null elements are evaluated. If the array itself is null, the function returns null.
Examples
Basic case with a null element:
-- Returns 1. The null element is skipped.
SELECT array_min(array(1, 20, null, 3));Related functions
ARRAY_MIN is a complex type function. For more information about functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.