Control reaches end of function without return

Control reaches end of function without return

Control reaches end of function without return

ERROR:  control reaches 
end of function without return

The cause of this error is the lack of execution of the command return in the function.

Wrong function

CREATE OR REPLACE FUNCTION 
update_customers(
p_first_name varchar, 
p_last_name varchar, 
p_type varchar(2)
)
RETURNS varchar AS $$
DECLARE
 v_result varchar(250);
 v_id numeric;
BEGIN
 SELECT id into v_id FROM customers 
 WHERE first_name = p_first_name 
 AND last_name = p_last_name;
 if v_id is not null then
	v_result:='OK customer';
	return v_result;
 end if;	
END;
$$LANGUAGE plpgsql;

Correct function

CREATE OR REPLACE FUNCTION 
update_customers(
p_first_name varchar, 
p_last_name varchar, 
p_type varchar(2)
)
RETURNS varchar AS $$
DECLARE
 v_result varchar(250);
 v_id numeric;
BEGIN
 SELECT id into v_id FROM customers 
 WHERE first_name = p_first_name 
 AND last_name = p_last_name;
 if v_id is not null then
	v_result:='OK customer';
 end if;	
 return v_result;
END;
$$LANGUAGE plpgsql;