LEVENSHTEIN_DISTANCE

All functions > STRING > LEVENSHTEIN_DISTANCE

Returns the Levenshtein (edit) distance between two strings.

Signatures

Returns: Minimum number of single-character edits (insertions, deletions, substitutions) required to change one string into the other

LEVENSHTEIN_DISTANCE(string1: VARCHAR, string2: VARCHAR) → BIGINT
sql
ParameterTypeRequiredDescription
string1VARCHARYesFirst string to compare
string2VARCHARYesSecond string to compare

Notes

  • Also known as edit distance
  • Case-sensitive comparison
  • Unlike Hamming distance, strings can be different lengths
  • Useful for fuzzy string matching and spell checking

Examples

FeatureQL
SELECT
    f1 := LEVENSHTEIN_DISTANCE('kitten', 'sitting'),  -- k->s, e->i, +g
    f2 := LEVENSHTEIN_DISTANCE('saturday', 'sunday'),  -- Complex transformation
    f3 := LEVENSHTEIN_DISTANCE('ABC', 'ABC'),  -- Identical strings
    f4 := LEVENSHTEIN_DISTANCE('abc', 'ABC')  -- Case-sensitive
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINT
3303

Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19