Skip to content

Commit bd6ca79

Browse files
committed
feat: add function to check if username is taken
Signed-off-by: Raphael Arce <[email protected]>
1 parent 4f8bcf6 commit bd6ca79

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE OR REPLACE FUNCTION is_username_taken(given_username text)
2+
RETURNS BOOLEAN AS $$
3+
DECLARE
4+
is_username_taken BOOLEAN;
5+
BEGIN
6+
-- Check if the username exists in the profile table
7+
SELECT EXISTS(SELECT 1 FROM public.profiles WHERE username = given_username) INTO is_username_taken;
8+
9+
-- Return the result
10+
RETURN is_username_taken;
11+
END;
12+
$$
13+
LANGUAGE plpgsql
14+
SECURITY DEFINER;

0 commit comments

Comments
 (0)