I am using a stored procedure to return the type of student that is enrolled at my college. Pushing their ID through should return their first name and last name in a new column that is going to be made(Ex: commuter, employee, resident). I keep getting an error:
ERROR: syntax error at or near "if" LINE 8: if exists (select count(commuterid) > 0 from commuter wh...).
Any tips or ideas?
create or replace function roleAtMarist(int, REFCURSOR) returns refcursor as
$$
declare
   identifier      int := $1;
   resultset refcursor := $2;
 begin
  open resultset for
    if exists (select count(commuterid) > 0 from commuter where commuterid = identifier) then
      select fname, lname, "Commuter" as Role
      from people 
      where peopleid = identifier;
    end if;
    if exists (select count(employeeid) > 0 from employee where emplpoyeeid = identifier) then
      select fname, lname, "Employee" as Role
      from people 
      where peopleid = identifier;
    end if;
    if exists (select count(residentid) > 0 from studentpark where residentid = identifier) then
      select fname, lname, "Resident" as Role
      from people 
      where peopleid = identifier;
    end if;
return resultset;
end; 
$$
language plpgsql; 
select roleAtMarist(12, 'resultset') ;
fetch all from results ;
 
    