---
title: array_compact function
description: Learn the syntax of the array\_distinct function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/array_compact
---

# `array_compact` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 12.2 LTS and above

Removes NULL elements from `array`.

## Syntax

```
array_compact(array)
```

## Arguments

* `array`: An ARRAY expression.

## Returns

The function returns an array of the same type as the input argument where all NULL values have been removed.

## Examples

```sql
> SELECT array_compact(array(1, 2, NULL, 3, NULL, 3));
 [1, 2, 3, 3]

> SELECT array_compact(array(NULL, NULL));
 []
```

## Related functions

* [`array_append` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_append.md)
* [`array_distinct` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_distinct.md)
* [`array_except` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_except.md)
* [`array_intersect` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_intersect.md)
* [`array_prepend` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_prepend.md)
* [`array_sort` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_sort.md)
* [`array_remove` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_remove.md)
* [`array_union` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_union.md)
