2020-08-17 08:00:24 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/grouparraysample
2022-04-09 13:29:05 +00:00
sidebar_position: 114
2020-08-17 08:00:24 +00:00
---
2022-06-02 10:55:18 +00:00
# groupArraySample
2020-08-17 08:00:24 +00:00
2021-07-29 15:20:55 +00:00
Creates an array of sample argument values. The size of the resulting array is limited to `max_size` elements. Argument values are selected and added to the array randomly.
2020-08-17 08:00:24 +00:00
**Syntax**
``` sql
2020-08-24 09:43:13 +00:00
groupArraySample(max_size[, seed])(x)
2020-08-17 08:00:24 +00:00
```
2021-02-15 21:33:53 +00:00
**Arguments**
2020-08-17 08:00:24 +00:00
2020-08-24 09:43:13 +00:00
- `max_size` — Maximum size of the resulting array. [UInt64 ](../../data-types/int-uint.md ).
- `seed` — Seed for the random number generator. Optional. [UInt64 ](../../data-types/int-uint.md ). Default value: `123456` .
- `x` — Argument (column name or expression).
2020-08-17 08:00:24 +00:00
**Returned values**
- Array of randomly selected `x` arguments.
Type: [Array ](../../data-types/array.md ).
**Examples**
Consider table `colors` :
``` text
┌─id─┬─color──┐
│ 1 │ red │
│ 2 │ blue │
│ 3 │ green │
│ 4 │ white │
│ 5 │ orange │
└────┴────────┘
```
2020-08-24 09:43:13 +00:00
Query with column name as argument:
2020-08-17 08:00:24 +00:00
``` sql
2020-08-24 09:43:13 +00:00
SELECT groupArraySample(3)(color) as newcolors FROM colors;
2020-08-17 08:00:24 +00:00
```
Result:
2020-08-24 09:43:13 +00:00
```text
┌─newcolors──────────────────┐
│ ['white','blue','green'] │
└────────────────────────────┘
2020-08-17 08:00:24 +00:00
```
2020-08-24 09:43:13 +00:00
Query with column name and different seed:
2020-08-17 08:00:24 +00:00
``` sql
2020-08-24 09:43:13 +00:00
SELECT groupArraySample(3, 987654321)(color) as newcolors FROM colors;
2020-08-17 08:00:24 +00:00
```
Result:
```text
2020-08-24 09:43:13 +00:00
┌─newcolors──────────────────┐
│ ['red','orange','green'] │
2020-08-17 08:00:24 +00:00
└────────────────────────────┘
```
2020-08-24 09:43:13 +00:00
Query with expression as argument:
2020-08-17 08:00:24 +00:00
``` sql
2020-08-24 09:43:13 +00:00
SELECT groupArraySample(3)(concat('light-', color)) as newcolors FROM colors;
2020-08-17 08:00:24 +00:00
```
Result:
```text
2020-08-24 09:43:13 +00:00
┌─newcolors───────────────────────────────────┐
│ ['light-blue','light-orange','light-green'] │
└─────────────────────────────────────────────┘
2020-08-17 08:00:24 +00:00
```