mirror of
https://github.com/jbranchaud/til
synced 2026-01-05 08:08:02 +00:00
Add Compute The Levenshtein Distance Of Two Strings as a postgres til
This commit is contained in:
21
postgres/compute-the-levenshtein-distance-of-two-strings.md
Normal file
21
postgres/compute-the-levenshtein-distance-of-two-strings.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Compute The Levenshtein Distance Of Two Strings
|
||||
|
||||
PostgreSQL has a built-in function for computing the [Levenshtein
|
||||
distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between two
|
||||
strings.
|
||||
|
||||
```sql
|
||||
> select levenshtein('hello', 'world');
|
||||
levenshtein
|
||||
-------------
|
||||
4
|
||||
|
||||
> select levenshtein('function', 'funtcion');
|
||||
levenshtein
|
||||
-------------
|
||||
2
|
||||
```
|
||||
|
||||
Check out the [`fuzzystrmatch`
|
||||
module](https://www.postgresql.org/docs/current/fuzzystrmatch.html#id-1.11.7.24.6)
|
||||
for more details.
|
||||
Reference in New Issue
Block a user