> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MAP_KEYS

> Returns the keys of a map as an array.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL for a NULL map.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
map_keys(map)
```

## Arguments

Type notation used below:

* K is the map key type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT.

| Name | Type | Required | Description |
| - | - | - | - |
| map | MAP\<K,V> | Yes | The map to inspect. A lookup key must have the map's key type after conversion. Map keys must be non-NULL. V is the map value type: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE, DECIMAL(p, s), STRING, BINARY, DATE, TIME, TIMESTAMP, ARRAY, MAP or STRUCT. Nested values retain their declared element/field types. |

## Returns

* Type: ARRAY\<K>
* Possible values: One key per map entry.
* NULL behavior: Returns NULL for a NULL map.
* Shape: Array length equals map entry count.
* Ordering: Underlying map entry order; no key sorting is performed.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* For ARRAY-valued keys or values, construct the input map with MAP\_FROM\_ARRAYS. The ordinary two-argument MAP constructor can interpret ARRAY arguments as parallel key/value lists.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT map_keys(map_from_arrays(ARRAY['a', 'b'], ARRAY[1, NULL])) AS "value";
```

| value |
| - |
| \["a","b"] |

### Integer map keys

This example shows the entries in this map; use an explicit sort when your query requires a particular key order.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT map_keys(map(10, 'red', 20, 'blue')) AS keys;
```

| keys |
| - |
| \[10,20] |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.