# timeSeriesGroupArray (/docs/reference/sql/aggregate-functions/timeseriesgrouparray)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Sorts time series data by timestamp in ascending order.

If several samples have the same timestamp, only one of them is used: the sample with the greatest value. A NaN value loses to any other value, so a NaN value is used only if all samples at this timestamp are NaN.

:::note
This function is experimental, enable it by setting `allow_experimental_ts_to_grid_aggregate_function=true`.
:::

**Syntax**

```sql
timeSeriesGroupArray(timestamp, value)
```

**Arguments**

* `timestamp` — Timestamp of the sample. [`DateTime`](/reference/data-types/datetime) or [`UInt32`](/reference/data-types/int-uint) or [`UInt64`](/reference/data-types/int-uint)
* `value` — Value of the time series corresponding to the timestamp. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal`](/reference/data-types/decimal)

**Returned value**

Returns an array of tuples `(timestamp, value)` sorted by timestamp in ascending order. [`Array(Tuple(T1, T2))`](/reference/data-types/array)

**Examples**

**Basic usage with individual values**

```sql title=Query
SET allow_experimental_time_series_aggregate_functions = 1;
WITH
    [110, 120, 130, 140, 140, 100]::Array(UInt32) AS timestamps,
    [1, 6, 8, 17, 19, 5]::Array(Float32) AS values
SELECT timeSeriesGroupArray(timestamp, value)
FROM
(
    SELECT
        arrayJoin(arrayZip(timestamps, values)) AS ts_and_val,
        ts_and_val.1 AS timestamp,
        ts_and_val.2 AS value
);
```

```text title=Response
┌─timeSeriesGroupArray(timestamp, value)───────────────┐
│ [(100, 5), (110, 1), (120, 6), (130, 8), (140, 19)]  │
└──────────────────────────────────────────────────────┘
```

**Passing multiple samples of timestamps and values as arrays of equal size**

```sql title=Query
SET allow_experimental_time_series_aggregate_functions = 1;
WITH
    [110, 120, 130, 140, 140, 100]::Array(UInt32) AS timestamps,
    [1, 6, 8, 17, 19, 5]::Array(Float32) AS values
SELECT timeSeriesGroupArray(timestamps, values);
```

```text title=Response
┌─timeSeriesGroupArray(timestamps, values)──────────────┐
│ [(100, 5), (110, 1), (120, 6), (130, 8), (140, 19)]   │
└───────────────────────────────────────────────────────┘
```

*Introduced in version 25.8.0.*
