EDITDISTANCE
functionsupportedCore SQL functionsComputes the Levenshtein distance between two input strings. It is the number of single-character insertions, deletions, or substitutions needed to convert one string to another. Note Unlike some other metrics (for example, Damerau-Levenshtein distance), character transpositions aren’t considered.
Syntax
supportedpartialnot supportednot scored
EDITDISTANCE( <string_expr1> , <string_expr2> [ , <max_distance> ] )
Parameters
| Name | Required | Description |
|---|---|---|
string_expr1, string_expr2 | required | The input strings. |
max_distance | optional | Integer expression that specifies the maximum distance to compute. When the distance between the strings exceeds this number, the function stops computing the distance and just returns the maximum distance. Specifying this argument has the same effect as calling LEAST( EDITDISTANCE( string_expr1, string_expr2 ), max_distance ). If you specify a negative number (that is, -n), the function uses 0 as the maximum distance and returns 0. |
Usage notes
- The execution time of the EDITDISTANCE function is proportional to the product of the lengths of the input strings.
- For better performance, Snowflake recommends using input strings not longer than 4096 characters. Input strings longer than 128 MB might result in an error. You can also use the optional max_distance argument to set an upper bound for the distance computed.
Collation details
No impact. In languages where the alphabet contains digraphs or trigraphs (such as “Dz” and “Dzs” in Hungarian), each character in each digraph and trigraph is treated as an independent character, not as part of a single multi-character letter. The result is based solely on the characters in the strings, not on the collation specifications of the strings.