EDIT_DISTANCE
Calculates and returns the Levenshtein distance between two strings.
Calculates and returns the Levenshtein distance between two strings. The return value indicates the minimum number of single-character edits—insertions, deletions, or substitutions—that are required to change one string into the other.
Behavior type
ImmutableSyntax
EDIT_DISTANCE ( string-expression1, string-expression2 )
Arguments
string-expression1
,string-expression2
- The two VARCHAR expressions to compare.
Examples
The Levenshtein distance between kitten
and knitting
is 3:
=> SELECT EDIT_DISTANCE ('kitten', 'knitting');
EDIT_DISTANCE
---------------
3
(1 row)
EDIT_DISTANCE calculates that no fewer than three changes are required to transform kitten
to knitting
:
-
kitten
→knitten
(insertn
afterk
) -
knitten
→knittin
(substitutei
fore
) -
knittin
→knitting
(appendg
)