---
schema_version: "1"
id: 48f6463f8ec462aaceb9b53993a7cff397067de73c9ecda34668b8735513b188
title: unnest
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-query-guide/references/data-cloud-sql-reference/set-returning-func/unnest.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/unnest.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 2c36625525c88a5e6997d4e5ebbddd7647d5f9f5d1b77677d07a884e945ec9c7
products:
  - Data 360 Query Guide
  - Data 360 Developer Documentation
---
# `unnest`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Expands the elements of one or more arrays into a set of rows.

## Syntax

```sql
unnest(<array> [, ...])
```

## Arguments

### Required

- `<array>`: The array to expand.

### Optional

- `...`: Additional arrays to expand in lock-step.

## Returns

Returns a set of rows, each containing one element from the array(s).
If multiple arrays are provided, they are expanded in lock-step.
If the arrays aren’t all the same length, the shorter ones are padded with NULL values.

## Examples

### Unnest an Array

```sql
SELECT * FROM unnest(ARRAY['Mon','Tue','Wed','Thu','Fri']) AS days(day)
```

Results:

| day |
| :-- |
| Mon |
| Tue |
| Wed |
| Thu |
| Fri |

### Unnest an Array while numbering the rows

The `WITH ORDINALITY` clause instructs `unnest` to also number the generated rows.
Thereby, we know which element occured at which position in the original array.

```sql
SELECT * FROM unnest(ARRAY['Mon','Tue','Wed','Thu','Fri']) WITH ORDINALITY AS days(day, ordinality)
```

Results:

| day | ordinality |
| :-- | :--------- |
| Mon | 1          |
| Tue | 2          |
| Wed | 3          |
| Thu | 4          |
| Fri | 5          |

### Unnest Multiple Arrays

You can also call `unnest` with multiple array parameters.
In this case, the arrays are expanded in lock-step.
If the arrays aren’t all the same length, the shorter ones are padded with NULL values.

```sql
SELECT * FROM unnest(
  ARRAY['Mon','Tue','Wed','Thu','Fri', 'Sat', 'Sun'],
  ARRAY['ramp up','work','work','work','wrap up'],
) AS days(name, task);
```

Results:

| name | task    |
| :--- | :------ |
| Mon  | ramp up |
| Tue  | work    |
| Wed  | work    |
| Thu  | work    |
| Fri  | wrap up |
| Sat  | NULL    |
| Sun  | NULL    |

## Related Documentation

- [Array Data Type](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/datatype/array.md)
- [Array Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/scalar-func/array-func/arrays.md)
- [Set Returning Functions](https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/set-returning-functions.md)
