ClickHouse/docs/en/sql-reference/aggregate-functions/reference/grouparray.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.3 KiB
Markdown
Raw Normal View History

---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/grouparray
sidebar_position: 110
---
2022-06-02 10:55:18 +00:00
# groupArray
Syntax: `groupArray(x)` or `groupArray(max_size)(x)`
Creates an array of argument values.
Values can be added to the array in any (indeterminate) order.
The second version (with the `max_size` parameter) limits the size of the resulting array to `max_size` elements. For example, `groupArray(1)(x)` is equivalent to `[any (x)]`.
2023-09-16 10:24:21 +00:00
In some cases, you can still rely on the order of execution. This applies to cases when `SELECT` comes from a subquery that uses `ORDER BY` if the subquery result is small enough.
2022-05-11 03:30:21 +00:00
**Example**
2022-05-16 01:28:39 +00:00
2022-05-11 03:30:21 +00:00
``` text
2022-05-16 01:29:30 +00:00
SELECT * FROM default.ck;
2022-05-11 03:30:21 +00:00
┌─id─┬─name─────┐
│ 1 │ zhangsan │
│ 1 │ ᴺᵁᴸᴸ │
│ 1 │ lisi │
│ 2 │ wangwu │
└────┴──────────┘
```
Query:
``` sql
2022-05-16 01:29:30 +00:00
select id, groupArray(10)(name) from default.ck group by id;
2022-05-11 03:30:21 +00:00
```
Result:
``` text
┌─id─┬─groupArray(10)(name)─┐
│ 1 │ ['zhangsan','lisi'] │
│ 2 │ ['wangwu'] │
└────┴──────────────────────┘
```
2022-05-16 01:27:58 +00:00
The groupArray function will remove ᴺᵁᴸᴸ value based on the above results.
- Alias: `array_agg`.