diff --git a/supabase/migrations/20241011145739_add_is_username_taken_function.sql b/supabase/migrations/20241011145739_add_is_username_taken_function.sql new file mode 100644 index 00000000..bef9a0b6 --- /dev/null +++ b/supabase/migrations/20241011145739_add_is_username_taken_function.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE FUNCTION is_username_taken(given_username text) +RETURNS BOOLEAN AS $$ +DECLARE + is_username_taken BOOLEAN; +BEGIN + -- Check if the username exists in the profile table + SELECT EXISTS(SELECT 1 FROM public.profiles WHERE username = given_username) INTO is_username_taken; + + -- Return the result + RETURN is_username_taken; +END; +$$ +LANGUAGE plpgsql +SECURITY DEFINER;