title: Using If else in posgreSQL function - syntax error
body: <p>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!</p>
  <pre><code>CREATE or replace FUNCTION sales_price(group_by text) 
  RETURNS table(first_name text, price decimal)
  AS $$
  
    IF group_by=&quot;x&quot; THEN
      select first_name, price from table1;
    ELSIF group_by=&quot;y&quot; THEN
      select first_name, price from table2;
    END IF;
  $$ LANGUAGE SQL IMMUTABLE;
  
  </code></pre>