> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8a08bda2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Creates an array of argument values. Values can be added to the array in any (indeterminate) order.

# groupArray

<h2 id="groupArray">
  groupArray
</h2>

Introduced in: v1.1.0

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)]`.

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.

The `groupArray` function will remove `NULL` values from the result.

**Syntax**

```sql theme={null}
groupArray(x)
groupArray(max_size)(x)
```

**Aliases**: `array_agg`

**Parameters**

* `max_size` — Optional. Limits the size of the resulting array to `max_size` elements. [`UInt64`](/reference/data-types/int-uint)

**Arguments**

* `x` — Argument values to collect into an array. [`Any`](/reference/data-types)

**Returned value**

Returns an array of argument values. [`Array`](/reference/data-types/array)

**Examples**

**Basic usage**

```sql title=Query theme={null}
SELECT id, groupArray(10)(name) FROM default.ck GROUP BY id;
```

```response title=Response theme={null}
┌─id─┬─groupArray(10)(name)─┐
│  1 │ ['zhangsan','lisi']  │
│  2 │ ['wangwu']           │
└────┴──────────────────────┘
```
