

# General list aggregate functions

Use these functions to run an aggregate function, such as `sum` or `max`, over the elements of one list instead of over rows. They handle `NULL` elements the way that the aggregate functions handle `NULL` rows, so most of them ignore `NULL` elements.

## `list_aggregate` function
<a name="athena-duckdb-functions-list-list-aggregate"></a>

Applies the aggregate function named `function_name` to the elements of `list`, as if the elements were the rows of a group, and returns the single result. For example, `list_aggregate({{list}}, 'min')` returns the smallest element. Any further arguments are passed to the aggregate function after the list elements, such as the separator for `string_agg` or the fraction for `quantile_cont`.

The aggregate function handles `NULL` elements as it does `NULL` rows, so most functions ignore them. For an empty list, the result is the aggregate's result for no rows, such as `NULL` for `sum` and `0` for `count`. If `list` is `NULL`, the result is `NULL`, even for `count`.

`aggregate`, `array_aggr`, `array_aggregate`, and `list_aggr` are aliases of `list_aggregate`.

### Syntax
<a name="athena-duckdb-functions-list-list-aggregate-syntax"></a>

```sql
list_aggregate({{list}}, {{function_name}} [, {{argument}}
    [, ...] ])
```

### Arguments
<a name="athena-duckdb-functions-list-list-aggregate-arguments"></a>

The `list_aggregate` function takes the following arguments:

**{{list}}**  
The list whose elements you want to aggregate, as a `LIST` or `ARRAY` value.

**{{function\_name}}**  
The name of an aggregate function, such as `'sum'`, `'max'`, or `'string_agg'`. It must be a constant `VARCHAR` value.

**{{argument}}**  
One or more further arguments for the aggregate function. This argument is optional.

### Return type
<a name="athena-duckdb-functions-list-list-aggregate-return-type"></a>

The return type of the aggregate function for the element type of `list`, for example `INTEGER` for `'min'` over an `INTEGER` list, and `HUGEINT` for `'sum'` over an `INTEGER` list.

### Examples
<a name="athena-duckdb-functions-list-list-aggregate-examples"></a>

The following SQL query returns the smallest element of a list. The `NULL` element is ignored.

```sql
SELECT list_aggregate([1, 2, NULL], 'min') AS result
```

The query returns the following result.


| result | 
| --- | 
| `1` | 

The following SQL query joins the elements of a list into one string with `string_agg`, and passes the separator `' | '` as a further argument.

```sql
SELECT
    list_aggregate(
        ['a', 'b', 'c'], 'string_agg', ' | '
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `a \| b \| c` | 

The following SQL query uses the `list_aggr` alias to sum a list of integers. The result type is `HUGEINT`.

```sql
SELECT list_aggr([2, 4, 8, 42], 'sum') AS result
```

The query returns the following result.


| result | 
| --- | 
| `56` | 

The following SQL query counts the elements of an empty list and of a `NULL` list. The empty list returns `0`, and the `NULL` list returns `NULL`.

```sql
SELECT
    list_aggregate(
        []::INTEGER[], 'count'
    ) AS empty_list,
    list_aggregate(
        NULL::INTEGER[], 'count'
    ) AS null_list
```

The query returns the following result.


| empty\_list | null\_list | 
| --- | --- | 
| `0` | `NULL` | 

### Considerations
<a name="athena-duckdb-functions-list-list-aggregate-considerations"></a>

`function_name` must be a constant. A column or other expression that changes from row to row makes the query fail.

Only aggregate functions work. A window-only function such as `row_number`, or a name that is not a function, makes the query fail.

## `list_approx_count_distinct` function
<a name="athena-duckdb-functions-list-list-approx-count-distinct"></a>

Applies the `approx_count_distinct` aggregate function to the elements of `list`, which estimates the number of distinct values. `NULL` elements are not counted. It is the same as `list_aggregate({{list}}, 'approx_count_distinct')`.

The result is an estimate, and for lists with many distinct values it can differ from the true count. For an exact count that also leaves out `NULL` elements, use `len(list_distinct({{list}}))`. For an empty list, the result is `0`. If `list` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-list-list-approx-count-distinct-syntax"></a>

```sql
list_approx_count_distinct({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-approx-count-distinct-arguments"></a>

The `list_approx_count_distinct` function takes the following argument:

**{{list}}**  
The list whose distinct elements you want to count, as a `LIST` or `ARRAY` value of any element type.

### Return type
<a name="athena-duckdb-functions-list-list-approx-count-distinct-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-list-list-approx-count-distinct-examples"></a>

The following SQL query estimates the number of distinct elements in a short list.

```sql
SELECT list_approx_count_distinct([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

The following SQL query shows that the `NULL` element is not counted, and that an empty list returns `0`.

```sql
SELECT
    list_approx_count_distinct(
        ['a', NULL, 'a', 'b']
    ) AS non_null_values,
    list_approx_count_distinct(
        []::VARCHAR[]
    ) AS empty_list
```

The query returns the following result.


| non\_null\_values | empty\_list | 
| --- | --- | 
| `2` | `0` | 

The following SQL query compares the estimate with the exact count for a list of 1,000 distinct integers. The estimate is close to the exact count, but not equal to it.

```sql
SELECT
    list_approx_count_distinct(
        generate_series(1, 1000)
    ) AS approximate,
    len(
        list_distinct(generate_series(1, 1000))
    ) AS exact
```

The query returns the following result.


| approximate | exact | 
| --- | --- | 
| `977` | `1000` | 

## `list_avg` function
<a name="athena-duckdb-functions-list-list-avg"></a>

Applies the `avg` aggregate function to the elements of `list` and returns their arithmetic mean. `NULL` elements are ignored. It is the same as `list_aggregate({{list}}, 'avg')`.

If `list` is empty, is `NULL`, or has only `NULL` elements, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-list-list-avg-syntax"></a>

```sql
list_avg({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-avg-arguments"></a>

The `list_avg` function takes the following argument:

**{{list}}**  
The list of values to average, as a `LIST` or `ARRAY` of numbers, or of `INTERVAL`, `TIMESTAMP`, or other values that `avg` accepts.

### Return type
<a name="athena-duckdb-functions-list-list-avg-return-type"></a>

`DOUBLE` for numeric elements, including `DECIMAL` elements. For time, timestamp, and interval elements, such as `TIME`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL`, the element type. For `DATE` elements, the result is a timestamp, not a `DATE`.

### Examples
<a name="athena-duckdb-functions-list-list-avg-examples"></a>

The following SQL query returns the average of a list of integers.

```sql
SELECT list_avg([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `5.0` | 

The following SQL query shows that the `NULL` element is ignored, so the average of `1` and `3` is `2.0`, and that an empty list returns `NULL`.

```sql
SELECT
    list_avg([1, NULL, 3]) AS with_null,
    list_avg([]::INTEGER[]) AS empty_list
```

The query returns the following result.


| with\_null | empty\_list | 
| --- | --- | 
| `2.0` | `NULL` | 

The following SQL query returns the midpoint of two timestamps.

```sql
SELECT
    list_avg(
        [
            TIMESTAMP '2026-10-01 00:00:00',
            TIMESTAMP '2026-10-03 00:00:00'
        ]
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2026-10-02 00:00:00` | 

### Considerations
<a name="athena-duckdb-functions-list-list-avg-considerations"></a>

For a list of `DECIMAL` values, the result is a `DOUBLE`, not a `DECIMAL`. Cast the result if you need a `DECIMAL`.

A list of strings makes the query fail.

## `list_bit_and` function
<a name="athena-duckdb-functions-list-list-bit-and"></a>

Combines the elements of `list` with a bitwise AND. A bit of the result is `1` only when that bit is `1` in every element. `NULL` elements are ignored. If `list` is `NULL`, is empty, or holds only `NULL` elements, the result is `NULL`.

`list_bit_and({{list}})` returns the same result as `list_aggregate({{list}}, 'bit_and')`. To combine values across rows instead of within one list, use the `bit_and` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-bit-and-syntax"></a>

```sql
list_bit_and({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-bit-and-arguments"></a>

The `list_bit_and` function takes the following argument:

**{{list}}**  
The list to combine with bitwise AND, as a list of integers, such as an `INTEGER[]` or `BIGINT[]` value, or a list of `BIT` values.

### Return type
<a name="athena-duckdb-functions-list-list-bit-and-return-type"></a>

The element type of `list`. For example, an `INTEGER[]` list returns an `INTEGER`.

### Examples
<a name="athena-duckdb-functions-list-list-bit-and-examples"></a>

The following SQL query combines `3` (binary `0011`), `3`, and `9` (binary `1001`). Only the lowest bit is set in all three values, so the result is `1`.

```sql
SELECT list_bit_and([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1` | 

The following SQL query shows that the `NULL` element is ignored. The bitwise AND of `12` (binary `1100`) and `10` (binary `1010`) is `8` (binary `1000`).

```sql
SELECT list_bit_and([12, 10, NULL]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `8` | 

The following SQL query shows that an empty list returns `NULL`.

```sql
SELECT
    list_bit_and(
        CAST([] AS INTEGER[])
    ) IS NULL AS is_null
```

The query returns the following result.


| is\_null | 
| --- | 
| `true` | 

### Considerations
<a name="athena-duckdb-functions-list-list-bit-and-considerations"></a>

The elements must be integers or `BIT` values. A list of decimals, such as `[1.5, 2.5]`, or a list of strings causes an error.

## `list_bit_or` function
<a name="athena-duckdb-functions-list-list-bit-or"></a>

Combines the elements of `list` with a bitwise OR. A bit of the result is `1` when that bit is `1` in at least one element. `NULL` elements are ignored. If `list` is `NULL`, is empty, or holds only `NULL` elements, the result is `NULL`.

`list_bit_or({{list}})` returns the same result as `list_aggregate({{list}}, 'bit_or')`. To combine values across rows instead of within one list, use the `bit_or` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-bit-or-syntax"></a>

```sql
list_bit_or({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-bit-or-arguments"></a>

The `list_bit_or` function takes the following argument:

**{{list}}**  
The list to combine with bitwise OR, as a list of integers, such as an `INTEGER[]` or `BIGINT[]` value, or a list of `BIT` values.

### Return type
<a name="athena-duckdb-functions-list-list-bit-or-return-type"></a>

The element type of `list`. For example, an `INTEGER[]` list returns an `INTEGER`.

### Examples
<a name="athena-duckdb-functions-list-list-bit-or-examples"></a>

The following SQL query combines `3` (binary `0011`), `3`, and `9` (binary `1001`) into `11` (binary `1011`).

```sql
SELECT list_bit_or([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `11` | 

The following SQL query combines single-bit flags into one value. The `NULL` element is ignored, and the bitwise OR of `1` and `4` is `5` (binary `0101`).

```sql
SELECT list_bit_or([1, NULL, 4]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `5` | 

### Considerations
<a name="athena-duckdb-functions-list-list-bit-or-considerations"></a>

The elements must be integers or `BIT` values. A list of decimals or a list of strings causes an error.

## `list_bit_xor` function
<a name="athena-duckdb-functions-list-list-bit-xor"></a>

Combines the elements of `list` with a bitwise exclusive OR. A bit of the result is `1` when that bit is `1` in an odd number of elements, so two equal values cancel each other out. `NULL` elements are ignored. If `list` is `NULL`, is empty, or holds only `NULL` elements, the result is `NULL`.

`list_bit_xor({{list}})` returns the same result as `list_aggregate({{list}}, 'bit_xor')`. To combine values across rows instead of within one list, use the `bit_xor` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-bit-xor-syntax"></a>

```sql
list_bit_xor({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-bit-xor-arguments"></a>

The `list_bit_xor` function takes the following argument:

**{{list}}**  
The list to combine with bitwise XOR, as a list of integers, such as an `INTEGER[]` or `BIGINT[]` value, or a list of `BIT` values.

### Return type
<a name="athena-duckdb-functions-list-list-bit-xor-return-type"></a>

The element type of `list`. For example, an `INTEGER[]` list returns an `INTEGER`.

### Examples
<a name="athena-duckdb-functions-list-list-bit-xor-examples"></a>

The following SQL query combines `3`, `3`, and `9`. The two `3` values cancel each other out, so the result is `9`.

```sql
SELECT list_bit_xor([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `9` | 

The following SQL query combines `5` (binary `0101`) and `3` (binary `0011`) into `6` (binary `0110`).

```sql
SELECT list_bit_xor([5, 3]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `6` | 

### Considerations
<a name="athena-duckdb-functions-list-list-bit-xor-considerations"></a>

The elements must be integers or `BIT` values. A list of decimals or a list of strings causes an error.

## `list_bool_and` function
<a name="athena-duckdb-functions-list-list-bool-and"></a>

Returns `true` when every element of `list` is `true`, and `false` when at least one element is `false`. `NULL` elements are ignored, so `[true, NULL]` returns `true`. If `list` is `NULL`, is empty, or holds only `NULL` elements, the result is `NULL`, not `true`.

`list_bool_and({{list}})` returns the same result as `list_aggregate({{list}}, 'bool_and')`. To test whether every element of a list meets a condition, turn the list into Boolean values with `list_transform` first, as in `list_bool_and(list_transform({{list}}, lambda x: x > 0))`.

### Syntax
<a name="athena-duckdb-functions-list-list-bool-and-syntax"></a>

```sql
list_bool_and({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-bool-and-arguments"></a>

The `list_bool_and` function takes the following argument:

**{{list}}**  
The list of Boolean values to test, as a `BOOLEAN[]` list.

### Return type
<a name="athena-duckdb-functions-list-list-bool-and-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-list-list-bool-and-examples"></a>

The following SQL query returns `false` because one element is `false`.

```sql
SELECT list_bool_and([true, false]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `false` | 

The following SQL query shows that a `NULL` element is ignored, and that an empty list returns `NULL`.

```sql
SELECT
    list_bool_and([true, NULL]) AS with_null,
    list_bool_and(
        CAST([] AS BOOLEAN[])
    ) IS NULL AS empty_is_null
```

The query returns the following result.


| with\_null | empty\_is\_null | 
| --- | --- | 
| `true` | `true` | 

The following SQL query tests whether every element is greater than 0. The `list_transform` function applies the lambda function `lambda x: x > 0` to each element `x` and returns a list of Boolean results.

```sql
SELECT
    list_bool_and(
        list_transform([1, 5], lambda x: x > 0)
    ) AS all_positive
```

The query returns the following result.


| all\_positive | 
| --- | 
| `true` | 

### Considerations
<a name="athena-duckdb-functions-list-list-bool-and-considerations"></a>

The elements must be `BOOLEAN` values. A list of integers, such as `[1, 0]`, or a list of strings, such as `['true', 'false']`, causes an error. Compare or cast the elements first.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-list-list-bool-and-differences-from-engine-version-3"></a>

Athena engine version 3 has `all_match({{array}}, {{function}})`. DuckDB has no `all_match` function, so write `list_bool_and(list_transform({{array}}, lambda x: {{condition}}))` instead. The two can return different results. When the condition is `NULL` for some elements and `true` for the rest, `all_match` returns `NULL`, but `list_bool_and` ignores the `NULL` results and returns `true`. For an empty array, `all_match` returns `true`, and `list_bool_and` returns `NULL`.

## `list_bool_or` function
<a name="athena-duckdb-functions-list-list-bool-or"></a>

Returns `true` when at least one element of `list` is `true`, and `false` when every element is `false`. `NULL` elements are ignored, so `[false, NULL]` returns `false`. If `list` is `NULL`, is empty, or holds only `NULL` elements, the result is `NULL`, not `false`.

`list_bool_or({{list}})` returns the same result as `list_aggregate({{list}}, 'bool_or')`. To test whether any element of a list meets a condition, turn the list into Boolean values with `list_transform` first, as in `list_bool_or(list_transform({{list}}, lambda x: x > 4))`.

### Syntax
<a name="athena-duckdb-functions-list-list-bool-or-syntax"></a>

```sql
list_bool_or({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-bool-or-arguments"></a>

The `list_bool_or` function takes the following argument:

**{{list}}**  
The list of Boolean values to test, as a `BOOLEAN[]` list.

### Return type
<a name="athena-duckdb-functions-list-list-bool-or-return-type"></a>

`BOOLEAN`

### Examples
<a name="athena-duckdb-functions-list-list-bool-or-examples"></a>

The following SQL query returns `true` because one element is `true`.

```sql
SELECT list_bool_or([true, false]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `true` | 

The following SQL query shows that a `NULL` element is ignored, and that an empty list returns `NULL`.

```sql
SELECT
    list_bool_or([false, NULL]) AS with_null,
    list_bool_or(
        CAST([] AS BOOLEAN[])
    ) IS NULL AS empty_is_null
```

The query returns the following result.


| with\_null | empty\_is\_null | 
| --- | --- | 
| `false` | `true` | 

The following SQL query tests whether any element is greater than 4, and whether no element is greater than 9. `list_transform` applies each lambda function to every element `x`.

```sql
SELECT
    list_bool_or(
        list_transform([1, 5], lambda x: x > 4)
    ) AS any_over_4,
    NOT list_bool_or(
        list_transform([1, 5], lambda x: x > 9)
    ) AS none_over_9
```

The query returns the following result.


| any\_over\_4 | none\_over\_9 | 
| --- | --- | 
| `true` | `true` | 

### Considerations
<a name="athena-duckdb-functions-list-list-bool-or-considerations"></a>

The elements must be `BOOLEAN` values. A list of integers or a list of strings causes an error. Compare or cast the elements first.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-list-list-bool-or-differences-from-engine-version-3"></a>

Athena engine version 3 has `any_match({{array}}, {{function}})` and `none_match({{array}}, {{function}})`. DuckDB has neither function. For `any_match`, write `list_bool_or(list_transform({{array}}, lambda x: {{condition}}))`, and for `none_match`, put `NOT` in front of that expression. The results can differ. When no element matches and the condition is `NULL` for some elements, `any_match` returns `NULL`, but `list_bool_or` ignores the `NULL` results and returns `false`. For an empty array, `any_match` returns `false`, and `list_bool_or` returns `NULL`.

When you replace `none_match` with `NOT list_bool_or(list_transform({{array}}, lambda x: {{condition}}))`, the results can also differ. When no element matches and the condition is `NULL` for some elements, `none_match` returns `NULL`, but the `NOT list_bool_or` expression returns `true`. For an empty array, `none_match` returns `true`, and the `NOT list_bool_or` expression returns `NULL`.

## `list_histogram` function
<a name="athena-duckdb-functions-list-list-histogram"></a>

Returns a `MAP` with one entry for each distinct element of `list` that is not `NULL`. The key is the element, and the value is the number of times that the element occurs in the list. The keys are in ascending order. `NULL` elements are not counted.

If `list` is empty, holds only `NULL` elements, or is `NULL`, the result is `NULL`, not an empty map.

`list_histogram({{list}})` returns the same result as `list_aggregate({{list}}, 'histogram')`. To count values across rows instead of within a list, use the `histogram` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-histogram-syntax"></a>

```sql
list_histogram({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-histogram-arguments"></a>

The `list_histogram` function takes the following argument:

**{{list}}**  
The list whose elements you want to count, with elements of any type.

### Return type
<a name="athena-duckdb-functions-list-list-histogram-return-type"></a>

`MAP({{T}}, UBIGINT)`, where `T` is the element type of `list`, for example `MAP(INTEGER, UBIGINT)` for an `INTEGER[]` list.

### Examples
<a name="athena-duckdb-functions-list-list-histogram-examples"></a>

The following SQL query counts the elements of a list.

```sql
SELECT list_histogram([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `{3=2, 9=1}` | 

The following SQL query counts strings. The `NULL` element is not counted, and the keys are in ascending order.

```sql
SELECT list_histogram(['b', 'a', 'b', NULL]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `{a=1, b=2}` | 

The following SQL query uses square brackets to look up the count for the key `'b'` in the map that `list_histogram` returns.

```sql
SELECT list_histogram(['b', 'a', 'b'])['b'] AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

The following SQL query shows that an empty list returns `NULL`, not an empty map.

```sql
SELECT
    list_histogram(
        CAST([] AS INTEGER[])
    ) IS NULL AS is_null
```

The query returns the following result.


| is\_null | 
| --- | 
| `true` | 

## `list_max` function
<a name="athena-duckdb-functions-list-list-max"></a>

Returns the largest element of `list`. `NULL` elements are ignored. If `list` is empty, holds only `NULL` elements, or is `NULL`, the result is `NULL`.

`list_max({{list}})` returns the same result as `list_aggregate({{list}}, 'max')`. To get the smallest element, use the [`list_min` function](#athena-duckdb-functions-list-list-min). To get the largest value across rows, use the `max` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-max-syntax"></a>

```sql
list_max({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-max-arguments"></a>

The `list_max` function takes the following argument:

**{{list}}**  
The list to search for the largest element, with elements of any type that can be ordered.

### Return type
<a name="athena-duckdb-functions-list-list-max-return-type"></a>

The element type of `list`, for example `INTEGER` for an `INTEGER[]` list.

### Examples
<a name="athena-duckdb-functions-list-list-max-examples"></a>

The following SQL query returns the largest element of a list.

```sql
SELECT list_max([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `9` | 

The following SQL query shows that a `NULL` element is ignored.

```sql
SELECT list_max([1, NULL, 5]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `5` | 

The following SQL query returns the latest date in a list.

```sql
SELECT
    list_max(
        [DATE '2026-10-01', DATE '2026-10-03']
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2026-10-03` | 

### Considerations
<a name="athena-duckdb-functions-list-list-max-considerations"></a>

Strings are compared by the code values of their characters, so uppercase letters sort before lowercase letters. For example, `list_max(['apple', 'Banana'])` returns `apple`. To compare strings without regard to case, convert them first, for example with `list_transform` and `lower`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-list-list-max-differences-from-engine-version-3"></a>

Athena engine version 3 uses `array_max`, which returns `NULL` when the array has a `NULL` element. In DuckDB, use `list_max`, which ignores `NULL` elements and returns the largest of the other elements. DuckDB has no `array_max` function.

## `list_min` function
<a name="athena-duckdb-functions-list-list-min"></a>

Returns the smallest element of `list`. `NULL` elements are ignored. If `list` is empty, holds only `NULL` elements, or is `NULL`, the result is `NULL`.

`list_min({{list}})` returns the same result as `list_aggregate({{list}}, 'min')`. To get the largest element, use the [`list_max` function](#athena-duckdb-functions-list-list-max). To get the smallest value across rows, use the `min` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-min-syntax"></a>

```sql
list_min({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-min-arguments"></a>

The `list_min` function takes the following argument:

**{{list}}**  
The list to search for the smallest element, with elements of any type that can be ordered.

### Return type
<a name="athena-duckdb-functions-list-list-min-return-type"></a>

The element type of `list`, for example `INTEGER` for an `INTEGER[]` list.

### Examples
<a name="athena-duckdb-functions-list-list-min-examples"></a>

The following SQL query returns the smallest element of a list.

```sql
SELECT list_min([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `3` | 

The following SQL query shows that a `NULL` element is ignored.

```sql
SELECT list_min([NULL, 4, 2]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

The following SQL query shows that string comparison is case sensitive. `Banana` sorts before `apple` because uppercase letters come first. The second column uses `list_transform` with the lambda function `lambda s: lower(s)`, which converts each element to lowercase, so the result is `apple`.

```sql
SELECT
    list_min(
        ['apple', 'Banana', 'cherry']
    ) AS case_sensitive,
    list_min(
        list_transform(
            ['apple', 'Banana', 'cherry'],
            lambda s: lower(s)
        )
    ) AS lowercased
```

The query returns the following result.


| case\_sensitive | lowercased | 
| --- | --- | 
| `Banana` | `apple` | 

### Considerations
<a name="athena-duckdb-functions-list-list-min-considerations"></a>

Strings are compared by the code values of their characters, so uppercase letters sort before lowercase letters. To compare strings without regard to case, convert them first, for example with `list_transform` and `lower`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-list-list-min-differences-from-engine-version-3"></a>

Athena engine version 3 uses `array_min`, which returns `NULL` when the array has a `NULL` element. In DuckDB, use `list_min`, which ignores `NULL` elements and returns the smallest of the other elements. DuckDB has no `array_min` function.

## `list_product` function
<a name="athena-duckdb-functions-list-list-product"></a>

Returns the product of the elements of `list`, as a `DOUBLE`. `NULL` elements are ignored. If `list` is empty, contains only `NULL` elements, or is `NULL`, the result is `NULL`.

`list_product({{list}})` returns the same result as `list_aggregate({{list}}, 'product')`. To multiply values across rows, use the `product` aggregate function.

### Syntax
<a name="athena-duckdb-functions-list-list-product-syntax"></a>

```sql
list_product({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-product-arguments"></a>

The `list_product` function takes the following argument:

**{{list}}**  
The list of numeric values to multiply. The values are converted to `DOUBLE`.

### Return type
<a name="athena-duckdb-functions-list-list-product-return-type"></a>

`DOUBLE`

### Examples
<a name="athena-duckdb-functions-list-list-product-examples"></a>

The following SQL query multiplies the elements of a list.

```sql
SELECT list_product([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `81.0` | 

The following SQL query ignores the `NULL` element and multiplies the other two.

```sql
SELECT list_product([2, NULL, 5]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `10.0` | 

The following SQL query passes an empty list, so the result is `NULL`.

```sql
SELECT list_product(CAST([] AS INTEGER[])) AS result
```

The query returns the following result.


| result | 
| --- | 
| `NULL` | 

## `list_string_agg` function
<a name="athena-duckdb-functions-list-list-string-agg"></a>

Returns the elements of `list` joined into one `VARCHAR` value, with a comma and no space between them. Elements that are not strings, such as numbers, are converted to `VARCHAR` first, and `NULL` elements are left out.

If `list` is empty, holds only `NULL` elements, or is itself `NULL`, the result is `NULL`, not an empty string. `list_string_agg({{list}})` returns the same result as `list_aggregate({{list}}, 'string_agg')`.

### Syntax
<a name="athena-duckdb-functions-list-list-string-agg-syntax"></a>

```sql
list_string_agg({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-string-agg-arguments"></a>

The `list_string_agg` function takes the following argument:

**{{list}}**  
The list whose elements you want to join, as a `LIST` value.

### Return type
<a name="athena-duckdb-functions-list-list-string-agg-return-type"></a>

`VARCHAR`

### Examples
<a name="athena-duckdb-functions-list-list-string-agg-examples"></a>

The following SQL query joins three strings.

```sql
SELECT list_string_agg(['a', 'b', 'c']) AS result
```

The query returns the following result.


| result | 
| --- | 
| `a,b,c` | 

The following SQL query leaves out a `NULL` element, and converts a list of numbers to one string.

```sql
SELECT
    list_string_agg(['a', NULL, 'c']) AS with_null,
    list_string_agg([1, 2, 3]) AS numbers
```

The query returns the following result.


| with\_null | numbers | 
| --- | --- | 
| `a,c` | `1,2,3` | 

The following SQL query shows that an empty list returns `NULL` from `list_string_agg`, and an empty string from `array_to_string`.

```sql
SELECT
    list_string_agg([]) IS NULL AS agg_is_null,
    array_to_string([], ',') = '' AS to_string_is_empty
```

The query returns the following result.


| agg\_is\_null | to\_string\_is\_empty | 
| --- | --- | 
| `true` | `true` | 

The following SQL query joins three strings with the separator `' | '` instead of a comma. It calls `list_aggregate` with `'string_agg'` and the separator.

```sql
SELECT
    list_aggregate(
        ['a', 'b', 'c'], 'string_agg', ' | '
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `a \| b \| c` | 

### Considerations
<a name="athena-duckdb-functions-list-list-string-agg-considerations"></a>

The separator is always a comma, and `list_string_agg` takes no separator argument. To use another separator, call `list_aggregate({{list}}, 'string_agg', {{separator}})` or `array_to_string({{list}}, {{separator}})`.

For an empty list, `list_string_agg` returns `NULL`, but `array_to_string` returns an empty string. To get an empty string from `list_string_agg`, use `coalesce(list_string_agg({{list}}), '')`.

## `list_sum` function
<a name="athena-duckdb-functions-list-list-sum"></a>

Adds up the elements of `list` that are not `NULL`. If `list` is empty, holds only `NULL` elements, or is itself `NULL`, the result is `NULL`, not `0`. To get `0` instead, use `coalesce(list_sum({{list}}), 0)`.

`list_sum({{list}})` returns the same result as `list_aggregate({{list}}, 'sum')`, and its result type follows the `sum` aggregate function. For a list of integers, the result is a `HUGEINT`, a 128-bit integer, so a sum of `BIGINT` values does not overflow. For a list of `BOOLEAN` values, the result is the number of `true` elements.

### Syntax
<a name="athena-duckdb-functions-list-list-sum-syntax"></a>

```sql
list_sum({{list}})
```

### Arguments
<a name="athena-duckdb-functions-list-list-sum-arguments"></a>

The `list_sum` function takes the following argument:

**{{list}}**  
The list to sum, as a `LIST` of numbers (`TINYINT`, `SMALLINT`, `INTEGER`, `BIGINT`, `HUGEINT`, `BIGNUM`, `DECIMAL`, `FLOAT`, or `DOUBLE`), or a `LIST` of `BOOLEAN` values.

### Return type
<a name="athena-duckdb-functions-list-list-sum-return-type"></a>

The result is `HUGEINT` for a list of `BOOLEAN` values or of integers up to `HUGEINT`, and `DECIMAL(38, {{s}})` for a list of `DECIMAL` values with scale `s`. It is `DOUBLE` for a list of `FLOAT` or `DOUBLE` values, and `BIGNUM` for a list of `BIGNUM` values.

### Examples
<a name="athena-duckdb-functions-list-list-sum-examples"></a>

The following SQL query adds up a list of integers.

```sql
SELECT list_sum([3, 3, 9]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `15` | 

The following SQL query skips a `NULL` element.

```sql
SELECT list_sum([1, NULL, 3]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `4` | 

The following SQL query shows that the sum of an empty list is `NULL`, and uses `coalesce` to return `0` instead.

```sql
SELECT
    list_sum([]) IS NULL AS empty_is_null,
    coalesce(list_sum([]), 0) AS with_default
```

The query returns the following result.


| empty\_is\_null | with\_default | 
| --- | --- | 
| `true` | `0` | 

The following SQL query adds up a list of `DECIMAL` values, so the result is an exact `DECIMAL` value.

```sql
SELECT list_sum([1.25, 2.50]) AS result
```

The query returns the following result.


| result | 
| --- | 
| `3.75` | 

### Considerations
<a name="athena-duckdb-functions-list-list-sum-considerations"></a>

`list_sum` does not convert strings to numbers, so a list of `VARCHAR` values makes the query fail. Cast the elements first, for example `list_sum(list_transform({{list}}, lambda s: CAST(s AS DECIMAL(10,2))))`.

A Hive table cannot store a `HUGEINT` column. When you write the sum of a list of integers to a Hive table, cast it, as in `CAST(list_sum({{list}}) AS BIGINT)`.