question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No function matches Levenshtein stored procedure

See original GitHub issue

Bug report

Describe the bug

Working with Supabase and on a Nuxt.js project, so far things are going very well, very enjoyable and getting a new found love for SQL again.

I’ve started getting to some interesting points of Supabase with stored procedures to perform fuzzysearches.

I have a resemblance of a search query that joins a table creates a concatenated string to compare to a given string to calculate the LEVENSHTEIN distance for search results that return something useful for user.

This procedure works well in the SQL explorer. (seen below)

I can’t seem to get my Supabase.js to perform the query, instead, it returns the below error message.

I have included as much information to help debug this.

stored procedure

CREATE OR REPLACE FUNCTION public.search_tracks(query text)
RETURNS TABLE(id text, artist text, title text, full_name text, distance int) AS $$
  SELECT tracks.id, artists.title AS artist, tracks.title, concat(artists.title, ' - ', tracks.title) AS full_name, LEVENSHTEIN(LOWER(CONCAT(artists.title, ' - ', tracks.title)), LOWER(query)) AS distance 
    FROM tracks 
  LEFT JOIN artists ON artists.id = tracks.artist
  ORDER BY distance ASC
  LIMIT 20;
$$ LANGUAGE SQL immutable;
{
  error: {
    hint: 'No function matches the given name and argument types. You might need to add explicit type casts.',
    details: null,
    code: '42883',
    message: 'function levenshtein(text, text) does not exist'
  },
  data: null,
  count: null,
  status: 404,
  statusText: 'Not Found',
  body: null
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

const resp = await $supabase
  .rpc('search_tracks', { query: 'test' })
  .select('*')

Expected behaviour

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macos
  • Browser (if applies) chrome
  • Version of supabase-js:
    • @supabase/postgrest-js@^0.26.1
    • @supabase/supabase-js@^1.3.4
  • Version of Node.js: v14.16.0

Additional context

CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA extensions;
CREATE TABLE public.artists (
    id character varying NOT NULL,
    title character varying NOT NULL,
);
CREATE TABLE public.tracks (
    id character varying NOT NULL,
    title character varying NOT NULL,
    artist character varying NOT NULL,
);
INSERT INTO artists (id, title) VALUES ('art_1', 'Daft Punk');
INSERT INTO tracks (id, title, artist) VALUES ('trk_1', 'Harder Faster Stronger', 'art_1');

Run the procedure

SELECT search_tracks('Daft Punk - hard fast strong');

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
steve-chavezcommented, Mar 17, 2021

Depending on the role you use to make the call, you might also need to add a grant usage:

grant usage on schema extensions to anon;
grant usage on schema extensions to authenticated;
0reactions
soedirgocommented, Sep 26, 2022

Am able to resolve the permission error with grants, so closing the issue.

create or replace function public.test_function() returns int as $$
  select extensions.levenshtein('a', 'b');
$$ language sql;
grant execute on function extensions.levenshtein(text, text) to anon, authenticated, service_role;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Damerau–Levenshtein distance algorithm in MySQL as a ...
I have found various procedure/function code examples that compares two specified strings and works out the distance, but firstly this is only ...
Read more >
Fuzzy strings matching using Levenshtein algorithm on SQL ...
Levenshtein algorithm calculates Levenshtein distance which is a metric for measuring a difference between two strings.
Read more >
levenshtein - Manual - PHP
The levenshtein function processes each byte of the input string individually. Then for multibyte encodings, such as UTF-8, it may give ...
Read more >
Azure SQL Server Fuzzy Logic Matching - Microsoft Q&A
Matching Score could be a score for how close a match they are. ... but I'm not sure if it's designed for large...
Read more >
String Matching With FuzzyWuzzy - Towards Data Science
This tutorial will go over how to match strings by their similarity. ... science process by providing tools such as the Levenshtein distance…...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found