I am trying to create a function to update the password of an user. Here is my function.
CREATE OR REPLACE FUNCTION update_user(userid int, upassword text) RETURNS integer AS $$
BEGIN
UPDATE tbl_user
SET password= upassword
WHERE user_id = userid;
SELECT 1;
END;
$$
LANGUAGE plpgsql;
And I tried to execute this functions using.
SELECT update_user(1, 'test');
I got an error as
ERROR: control reached end of function without RETURN CONTEXT: PL/pgSQL function
I'm not sure where I go wrong. Please help me on this. I'm new to creating functions. Thanks in advance.
RETURNS integer, but you don't tell it what to return. What do you expect it to do?GET DIAGNOSTICS. But I really don't understand why you're wrapping the statement in a function like this, rather than just doing that directly in the call site.