> ## 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.

# LEVENSHTEIN

> Counts the edits needed to transform one string into another.

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

Returns NULL when either string or a supplied threshold is NULL.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
levenshtein(left, right [, threshold])
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| left | STRING | Yes | The first string. |
| right | STRING | Yes | The second string. |
| threshold | INTEGER | No | An optional maximum accepted distance. Default: No upper threshold. |

## Returns

* Type: INT
* Possible values: A nonnegative edit distance, or -1 when the distance exceeds threshold.
* NULL behavior: Returns NULL when either string or a supplied threshold is NULL.

## Properties

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

## Usage notes

* Insertion, deletion and substitution each cost one edit. Distances count Unicode code points.
* A negative threshold causes a non-NULL input pair to return -1.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT levenshtein('kitten', 'sitting') AS distance, levenshtein('kitten', 'sitting', 2) AS threshold_result;
```

| distance | threshold\_result |
| - | - |
| 3 | -1 |

### Empty and identical strings

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT levenshtein('', 'cat') AS insertions, levenshtein('cat', 'cat') AS unchanged;
```

| insertions | unchanged |
| - | - |
| 3 | 0 |


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