Time series functions

**Returned value**

Returns the identifier of a time series (i.e. just the first argument).

**Examples**

**Example**

```
SELECT 8374283493092 AS id,
       timeSeriesStoreTags(id, [('region', 'eu'), ('env', 'dev')], '__name__', 'http_requests_count') AS same_id,
       throwIf(same_id != id),
       timeSeriesIdToTags(same_id),
       timeSeriesGroupToTags(timeSeriesIdToGroup(same_id))
```

```
┌────────────id─┬───────same_id─┬─throwIf(notEquals(same_id, id))─┬─timeSeriesIdToTags(same_id)────────────────────────────────────────┬─timeSeriesGroupToTags(timeSeriesIdToGroup(same_id))────────────────┐
│ 8374283493092 │ 8374283493092 │                               0 │ [('__name__','http_requests_count'),('env','dev'),('region','eu')] │ [('__name__','http_requests_count'),('env','dev'),('region','eu')] │
└───────────────┴───────────────┴─────────────────────────────────┴────────────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────┘
```

## timeSeriesTagsToGroup[​](#timeSeriesTagsToGroup "Direct link to timeSeriesTagsToGroup")

Introduced in: v26.1.0

Returns a group of tags associated with specified tags.
If the same group of tags is found multiple times during the query execution, the function returns the same group.
For an empty set of tags the function always returns 0.
See also function [timeSeriesGroupToTags()](/docs/sql-reference/functions/time-series-functions#timeSeriesGroupToTags).

**Syntax**

```
timeSeriesTagsToGroup(tags_array, tag_name_1, tag_value_1, tag_name2, tag_value2, ...)
```

**Arguments**

- `tags_array` — Array of pairs (tag\_name, tag\_value). [`Array(Tuple(String, String))`](/docs/sql-reference/data-types/array) or [`NULL`](/docs/sql-reference/syntax#null)
- `tag_name_i` — The name of a tag. [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring)
- `tag_value_i` — The value of a tag. [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring) or [`Nullable(String)`](/docs/sql-reference/data-types/nullable)

**Returned value**

Returns a group of tags associated with the specified tags. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Example**

```
SELECT timeSeriesTagsToGroup([('region', 'eu'), ('env', 'dev')], '__name__', 'http_requests_count') AS group1,
       timeSeriesTagsToGroup([], '__name__', 'http_failures') AS group2,
       timeSeriesTagsToGroup([]) AS empty_group,
       timeSeriesTagsToGroup([], '__name__', 'http_failures') AS same_group2,
       throwIf(same_group2 != group2),
       timeSeriesGroupToTags(group2)
```

```
┌─group1─┬─group2─┬─empty_group─┬─same_group2─┬─throwIf(notEquals(same_group2, group2))─┬─timeSeriesGroupToTags(group2)──┐
│      1 │      2 │           0 │           2 │                                       0 │ [('__name__','http_failures')] │
└────────┴────────┴─────────────┴─────────────┴─────────────────────────────────────────┴────────────────────────────────┘
```

## timeSeriesThrowDuplicateSeriesIf[​](#timeSeriesThrowDuplicateSeriesIf "Direct link to timeSeriesThrowDuplicateSeriesIf")

Introduced in: v26.2.0

Checks the `condition` and if it's true throws an exception with the following message
`Multiple series have the same tags <tags>, duplicate series in the same result set are not allowed`.
If the `condition` is false the function returns `0`.
This function is similar to [throwIf()](/docs/sql-reference/functions/other-functions#throwIf),
but uses a different error code and formats the error message differently.

**Syntax**

```
timeSeriesThrowDuplicateSeriesIf(condition, group)
```

**Arguments**

- `condition` — Condition to check, usually contains function [count()](/docs/sql-reference/aggregate-functions/reference/count#count) [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `group` — Group of tags. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns `0`. [`UInt8`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Example**

```
CREATE TABLE test(tags Array(Tuple(String, String))) engine=Memory;

INSERT INTO test VALUES ([('__name__', 'up')]);

SELECT timeSeriesTagsToGroup(tags) AS group
FROM test
GROUP BY group
HAVING timeSeriesThrowDuplicateSeriesIf(count() > 1, group) = 0;  -- OK

INSERT INTO test VALUES ([('__name__', 'up')]);

SELECT timeSeriesTagsToGroup(tags) AS group
FROM test
GROUP BY group
HAVING timeSeriesThrowDuplicateSeriesIf(count() > 1, group) = 0;  -- Throws exception "Multiple series have the same tags {'__name__': 'up'}"
```

- [seriesDecomposeSTL](#seriesDecomposeSTL)- [seriesOutliersDetectTukey](#seriesOutliersDetectTukey)- [seriesPeriodDetectFFT](#seriesPeriodDetectFFT)- [timeSeriesCopyTag](#timeSeriesCopyTag)- [timeSeriesCopyTags](#timeSeriesCopyTags)- [timeSeriesExtractTag](#timeSeriesExtractTag)- [timeSeriesFromGrid](#timeSeriesFromGrid)- [timeSeriesGroupToTags](#timeSeriesGroupToTags)- [timeSeriesIdToGroup](#timeSeriesIdToGroup)- [timeSeriesIdToTags](#timeSeriesIdToTags)- [timeSeriesJoinTags](#timeSeriesJoinTags)- [timeSeriesRange](#timeSeriesRange)- [timeSeriesRemoveAllTagsExcept](#timeSeriesRemoveAllTagsExcept)- [timeSeriesRemoveTag](#timeSeriesRemoveTag)- [timeSeriesRemoveTags](#timeSeriesRemoveTags)- [timeSeriesReplaceTag](#timeSeriesReplaceTag)- [timeSeriesStoreTags](#timeSeriesStoreTags)- [timeSeriesTagsToGroup](#timeSeriesTagsToGroup)- [timeSeriesThrowDuplicateSeriesIf](#timeSeriesThrowDuplicateSeriesIf)

Was this page helpful?