0

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.

ChrisM
  • 1,576
  • 6
  • 18
  • 29

1 Answers1

0

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.

Gherbi Hicham
  • 2,416
  • 4
  • 26
  • 41
  • 1
    Thanks for the answer it helped finding the solution. Basically the thing that confused me the most was the fact that i had a function defined with those parameters but the system didn't manage to get it. I just realize that the SQL definition of that function was simply a reference to that module i was missing. – Davide Barbieri Nov 15 '17 at 14:47