---
title: "[ ] (bracket sign) operator"
description: Learn the syntax of the \[ ] (bracket sign) operator of the SQL language in Databricks SQL.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/bracketsign
---

# `[ ]` (bracket sign) operator

**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 an array element or map value given an index or key.

## Syntax

```
expr [ keyExpr ]
```

Note that the use of brackets here is as literal text and not indicating optional syntax.

## Arguments

* `expr`: An ARRAY or MAP expression.
* `keyExpr`: If `expr` is an ARRAY an integral numeric.
  Otherwise an expression matching the type of the key of the MAP.

## Returns

The result type is the element type of the ARRAY or the value type of the MAP.

The first element of an ARRAY is at index 0.

If the `keyExpr` is not a valid key for the MAP `expr` Databricks returns null.

If the `keyExpr` is out of bound for the ARRAY `expr`, Databricks raises an [INVALID\_ARRAY\_INDEX](https://docs.databricks.com/aws/en/error-messages/invalid-array-index-error-class.md) error.

> [!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`, the operator returns `NULL` instead of an out of bounds error.

## Common error conditions

* [INVALID\_ARRAY\_INDEX](https://docs.databricks.com/aws/en/error-messages/invalid-array-index-error-class.md)

## Examples

```sql
> SELECT a[2] FROM VALUES(array(10, 20, 30)) AS T(a);
  30

> SELECT m[1] FROM VALUES(map(1, 'Hello', 2, 'World')) AS T(m);
  Hello

> SELECT array(1, 2, 3)[5];
  Error: INVALID_ARRAY_INDEX
```

## Related functions

* [`array` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array.md)
* [`array_contains` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_contains.md)
* [`array_position` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/array_position.md)
* [`map` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map.md)
* [`map_keys` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_keys.md)
* [`map_values` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/map_values.md)
