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

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

Transforms keys in a map in `expr` using the function `func`.

## Syntax

```
transform_keys(expr, func)
```

## Arguments

* `expr`: A MAP expression.
* `func`: A lambda function.

## Returns

A MAP where the keys have the type of the result of the lambda functions and the values have the type of the `expr` MAP values.

The lambda function must have 2 parameters.
The first parameter represents the key.
The second parameter represents the value.

The lambda function produces a new key for each entry in the map.

Databricks raises [DUPLICATED\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#duplicated_map_key) if the lambda function produces duplicate keys.

## Common error conditions

* [DUPLICATED\_MAP\_KEY](https://docs.databricks.com/aws/en/error-messages/error-classes.md#duplicated_map_key)

## Examples

```sql
> SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + 1);
 {2 -> 1, 3 -> 2, 4 -> 3}
> SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
 {2 -> 1, 4 -> 2, 6 -> 3}

-- The transform produces duplicate key 0 from both entries.
> SELECT transform_keys(map(1, 'a', 2, 'b'), (k, v) -> 0);
  Error: DUPLICATED_MAP_KEY
```

## Related functions

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