No function matches Levenshtein stored procedure
See original GitHub issueBug 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:
- Created 3 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Depending on the role you use to make the call, you might also need to add a grant usage:
Am able to resolve the permission error with grants, so closing the issue.