Search code examples
hibernatehql

Missing fuzzystringmatch extension pg admin


I had a problem recentley with the following output from java with hibernate trying to execute a query.

Caused by: org.postgresql.util.PSQLException: ERRORE: la funzione levenshtein_less_equal(text, character varying, integer) non esiste
  Suggerimento: Nessuna funzione trovata con nome e tipi di argomenti forniti. Potrebbe essere necessario convertire i tipi esplicitamente.
  Posizione: 464

Sorry for the italian log for error, basically says that function doesn't exists with that kind of parameters. I checked on my functions on the DB and I had a function called:

levenshtein_less_equal(text, text, integer)

Now, first I don't understand why query.setparameter on java, which sets both the 1st and the 2nd argument of the function with a string would end up with such function call

levenshtein_less_equal(text, character varying, integer)

Both are strings but one is mapped to text and one to character varying??

Second I don't understand why I solved this by adding the fuzzystrmatch extension to the DB extensions.


Solution

  • levenshtein_less_equal(text, text, integer) is a function to compare two strings in postgres, it's part of the Fuzzymatch module that contains functions to get the distance between strings see: fuzzystrmatch, one of the ways to compare string is called the Levenshtein distance.

    When you do setParameter()in Hibernate you indirectly trigger a string comparison, I don't see your data but I think your data has special characters, here is a link to a stack overflow question that disscusses the same problem: link.

    So what is basically happening here is that Postgres is trying to get an approximation for the strings that it doesn't understand in order to get a match and it's using the Levenshtein Distance to do so.