Skip to content

DLE_DST

Return the difference between two character strings in terms of the number of changes required to convert the first string into the second. The comparison of the strings is case-sensitive. This function uses the Damerau-Levenshtein edit distance algorithm to compute the "distance" between the strings. With this algorithm, a character transposition change such as 'ab' to 'ba' counts as one change, not two.

See also LE_DST.

Usage Notes

This function returns an integer.

Two configuration parameters affect the performance and memory usage of this function. See max_levenshtein_distance and max_levenshtein_string_size for more information.

Examples

The following example requires two changes, one for the case of the letter C, and one for the transposition of kc:

yellowbrick=# select dle_dst('Chekcing','checking') from sys.const;
 le_dst 
--------
     2
(1 row)

Calculate the distance between London team names and their nicknames in the team table:

premdb=# select name, nickname, dle_dst(name,nickname) dledst from team where city='London' and name is not null order by 3 desc;
       name         |  nickname  | dledst 
---------------------+------------+--------
 Queens Park Rangers | Hoops      |     18
 Charlton Athletic   | Addicks    |     16
 Tottenham Hotspur   | Spurs      |     15
 West Ham United     | Hammers    |     12
 Crystal Palace      | Eagles     |     12
 Wimbledon           | Dons       |      8
 Chelsea             | Pensioners |      8
 Fulham              | Cottagers  |      8
 Arsenal             | Gunners    |      6
(9 rows)

See also the examples for LE_DST.