ComeçarComece de graça

Levenshtein distance examples

Now let's take a closer look at how we can use the levenshtein function to match strings against text data. If you recall, the levenshtein distance represents the number of edits required to convert one string to another string being compared.

In a search application or when performing data analysis on any data that contains manual user input, you will always want to account for typos or incorrect spellings. The levenshtein function provides a great method for performing this task. In this exercise, we will perform a query against the film table using a search string with a misspelling and use the results from levenshtein to determine a match. Let's check it out.

Este exercício faz parte do curso

Functions for Manipulating Data in PostgreSQL

Ver curso

Instruções do exercício

  • Select the film title and film description.
  • Calculate the levenshtein distance for the film title with the string JET NEIGHBOR.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

-- Select the title and description columns
SELECT  
  ___, 
  ___, 
  -- Calculate the levenshtein distance
  ___(___, ___) AS distance
FROM 
  film
ORDER BY 3
Editar e executar o código