getting the wrong response 'user already exists' in the table, there is no user exists and I checked my SP but it looks like all is right.
here is my SP can anyone point out what is wrong?
CREATE OR REPLACE FUNCTION user_register( IN p_email VARCHAR(255),
IN p_password VARCHAR(255), IN first_name VARCHAR(255),
IN last_name VARCHAR(255))
RETURNS TEXT AS $$DECLARE
v_user_exists BOOLEAN;BEGIN
SELECT TRUE INTO v_user_exists
FROM public.subscribe_user WHERE TRIM(LOWER(email)) = TRIM(LOWER(p_email));
IF NOT v_user_exists THEN
INSERT INTO public.subscribe_user(email, password, first_name, last_name)
VALUES (p_email, crypt(p_password, gen_salt('bf')), first_name, last_name);
RETURN 'Registration successful'; ELSE
RETURN 'User already exists'; END IF;
END;$$ LANGUAGE plpgsql;
you should change it to: if v_user_exists then ... else ... end if;
Обсуждают сегодня