i have this function when a user signs up I insert some data to the profiles table,after that, I want to generate a code digit and insert it into the paring_codes tablebut I got this error in LOGs
CREATE OR REPLACE FUNCTION generate_unique_code(user_id UUID)
RETURNS VARCHAR AS $$
BEGIN
RETURN md5(user_id::TEXT || RANDOM()::TEXT);
END;
$$ LANGUAGE plpgsql;`
-- Trigger Function to Handle New User Sign Up
CREATE OR REPLACE FUNCTION handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO public.profiles (id, username)
VALUES (NEW.id, NEW.raw_user_meta_data->>'username');
INSERT INTO public.pairing_codes (code, user_id)
VALUES (generate_unique_code(NEW.id), NEW.id);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
"error": "failed to close prepared statement: ERROR: current transaction is aborted, commands ignored until end of transaction block (SQLSTATE 25P02): ERROR: function generate_unique_code(uuid) does not exist (SQLSTATE 42883)"
I'd recommend updating the functions to reference the specific schema where you'd like them defined: public.generate_unique_code()
and public.handle_new_user()
.