Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Fsetunion.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Farray%2Fsetunion.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `setUnion`

## Description

Returns the union of two arrays, producing a new array that contains all unique elements from both.

* Both arrays are treated as sets:

- Duplicates are removed
- Order is not preserved in the result
- `null` is treated as an empty set
- Supported element types include `string`, `bool`, `number`, `interval`, `timestamp`, `regexp`, and `enum`.

## Syntax

Like many functions in DataPrime, `setUnion` supports<!-- --> [two notations](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
setUnion(array1: array<T>, array2: array<T>): array<T>
```

```
(array1: array<T>).setUnion(array2: array<T>): array<T>
```

## Arguments

| Name     | Type       | Required | Description                 |
| -------- | ---------- | -------- | --------------------------- |
| `array1` | `array<T>` | **true** | The first array to combine  |
| `array2` | `array<T>` | **true** | The second array to combine |

## Example

**Use case: Combine processing and loading jobs into a unique set**

Suppose you have arrays of processing and loading jobs. Consider the following input:

```
{

    "processing_jobs_waiting": ["job1", "job2", "job3", "job4"],

    "loading_jobs_waiting": ["job1", "job2", "job3"]

}
```

By applying `setUnion`, you can merge the two arrays and keep only unique jobs.

### Example query

* Function notation
* Method notation

```
create all_jobs from setUnion(processing_jobs_waiting, loading_jobs_waiting)
```

```
create all_jobs from processing_jobs_waiting.setUnion(loading_jobs_waiting)
```

### Example output

The result will include a new field `all_jobs` containing unique values from both arrays:

```
{

    "processing_jobs_waiting": ["job1", "job2", "job3"],

    "loading_jobs_waiting": ["job1", "job2", "job3"],

    "all_jobs": ["job1", "job2", "job3", "job4"]

}
```
