I am trying to check if a userhandle already exists in the database as part of registration process of my users (the userhandle has to be unique). I am using Hasura and trying to write a custom SQL function that should return a boolean (true or false if the userhandle already exists).
I am getting errors at "EXISTS" here, can I somehow use EXISTS to return a boolean if the userhandle exists in the table or not? In Hasura I have to return a BASE type, which means Boolean should be OK (I think). Would greatly appreciate any help!
CREATE FUNCTION userhandle_exist(users_row users, search text)
RETURNS BOOLEAN AS $$
EXISTS(SELECT * FROM users WHERE users.userhandle = search)
$$ LANGUAGE sql STABLE;