Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : function levenshtein() does not exist

Tags:

postgresql

I am using levenshtein() function in my SQL script. I am using Postgresql database and client to execute the script. It's throwing an error:

function levenshtein(character varying, character varying) does not exist. HINT : No function matches the given name and argument types. You might need to add explicit type casts.

I know the common solution to it i.e creating extensions like 'fuzzystrmatch' which I already did and strange thing is that the same script ran smoothly 4 days ago when I created fuzzystrmatch extension in the first place!

Below is my line of code where levenshtein() is used.

as $$select (1.0 - levenshtein($1, $2)::real/greatest(length($1), length($2)))::real;$$;
like image 765
Sahil Doshi Avatar asked Dec 23 '22 20:12

Sahil Doshi


1 Answers

This SQL command tells you where the extension is currently installed:

SELECT n.nspname
FROM pg_extension e
   JOIN pg_namespace n
      ON e.extnamespace = n.oid
WHERE e.extname = 'fuzzystrmatch';

If that not on your search_path, your query will not find the function.

To have the extension in a different schema, in the following example public, drop and recreate it:

DROP EXTENSION fuzzystrmatch;
CREATE EXTENSION fuzzystrmatch SCHEMA public;
like image 82
Laurenz Albe Avatar answered Jan 11 '23 23:01

Laurenz Albe