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

# `size` 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

Returns the cardinality of the array or map in `expr`.

## Syntax

```
size(expr)
```

## Arguments

* `expr`: An `ARRAY` or `MAP` expression.

## Returns

An `INTEGER`.

> [!NOTE]
>
> In Databricks Runtime, if [spark.sql.ansi.enabled](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-ansi-compliance.md) is `false`, `size(NULL)` returns `-1` instead of `NULL`.

## Examples

```sql
> SELECT size(array('b', 'd', 'c', 'a'));
 4
> SELECT size(map('a', 1, 'b', 2));
 2
> SELECT size(NULL);
 -1
```

## Related functions

* [`length` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/length.md)
