I am trying to create a function that will execute different SQL based on provided input to the function (i.e. IF ELSE). I am trying something like below but keep getting a syntax error. Does anyone know what I am doing wrong? Any pointers will be greatly appreciated!
CREATE or replace FUNCTION sales_price(group_by text)
RETURNS table(first_name text, price decimal)
AS $$
IF group_by="x" THEN
select first_name, price from table1;
ELSIF group_by="y" THEN
select first_name, price from table2;
END IF;
$$ LANGUAGE SQL IMMUTABLE;