> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# aggregate_* session settings

> ClickHouse session settings in the aggregate_* generated group.

These settings are available in [system.settings](https://clickhouse.com/docs/reference/system-tables/settings.md) and are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).

## aggregate\_function\_input\_format

Type

AggregateFunctionInputFormat

Default

state

How the input formats read columns of the `AggregateFunction` type.

Possible values:

* `state` — the serialized state of the aggregate function, as the output formats write it (the default).
* `value` — a value of the argument of the aggregate function, or a tuple of the arguments if there are several of them. The value is aggregated to form the state.
* `array` — an array of values, as described in the `value` option above. All elements of the array are aggregated to form the state.

In the `value` and `array` modes the format reads the column as if it had the type of the values: `T` for `AggregateFunction(f, T)`, `Tuple(T1, T2)` for `AggregateFunction(f, T1, T2)`, or `Array` of it in the `array` mode. The values are written in the representation the format uses for that type: a number or a string in a text format, a JSON array in the JSON formats, the binary encoding of the type in `RowBinary` or `Native`, a column of that type in `Parquet`, and so on. This applies to every input format, and also to `AggregateFunction` nested in `Array`, `Tuple` or `Map`.

**Examples**

For a table with structure:

```sql theme={null}
CREATE TABLE example (
    user_id UInt64,
    avg_session_length AggregateFunction(avg, UInt32)
);
```

With `aggregate_function_input_format = 'value'`:

```sql theme={null}
INSERT INTO example FORMAT CSV
123,456
```

```sql theme={null}
INSERT INTO example FORMAT JSONEachRow
{"user_id": 123, "avg_session_length": 456}
```

With `aggregate_function_input_format = 'array'`:

```sql theme={null}
INSERT INTO example FORMAT CSV
123,"[456,789,101]"
```

```sql theme={null}
INSERT INTO example FORMAT JSONEachRow
{"user_id": 123, "avg_session_length": [456, 789, 101]}
```

Note: The `value` and `array` formats are slower than the default `state` format as they require creating and aggregating values during insertion.

## aggregate\_functions\_null\_for\_empty

Type

Bool

Default

0

Enables or disables rewriting all aggregate functions in a query, adding [-OrNull](https://clickhouse.com/docs/reference/functions/aggregate-functions/combinators.md#-ornull) suffix to them. Enable it for SQL standard compatibility.
It is implemented via query rewrite (similar to [count\_distinct\_implementation](https://clickhouse.com/docs/reference/settings/session-settings/count-distinct.md#count_distinct_implementation) setting) to get consistent results for distributed queries.

Possible values:

* 0 — Disabled.
* 1 — Enabled.

**Example**

Consider the following query with aggregate functions:

```sql theme={null}
SELECT SUM(-1), MAX(0) FROM system.one WHERE 0;
```

With `aggregate_functions_null_for_empty = 0` it would produce:

```text theme={null}
┌─SUM(-1)─┬─MAX(0)─┐
│       0 │      0 │
└─────────┴────────┘
```

With `aggregate_functions_null_for_empty = 1` the result would be:

```text theme={null}
┌─SUMOrNull(-1)─┬─MAXOrNull(0)─┐
│          NULL │         NULL │
└───────────────┴──────────────┘
```
