PostgreSQL IF – Then – Else syntax

IF Else

Syntax and examples of conditional IF – Then – Else.

CREATE OR REPLACE FUNCTION 
	get_result(in p_name varchar(2)) 
RETURNS varchar AS $$
DECLARE
	v_name varchar(50);
BEGIN
	if p_name = 'A' then
		v_name:='The name is A';
		return v_name;
	else
		v_name:='The name is X';
		return v_name;
	end if;		
END;
$$ LANGUAGE 'plpgsql' IMMUTABLE;