title: Postgres: unable to create function
body: <p>I need to write a very simple function. I will pass three parameters(employeeid, employeetitle and employeeaddress). If passed employeeid is equal to 0, a new record will be inserted into the table. If the employeeid passed is greater than 0 the record will be updated. In both the cases employeeid will be returned as result(id is auto increment value in employee table). I am using pgAdmin and here is the code I have written:</p>
  
  <pre><code>CREATE FUNCTION public.addupdateemployee(IN employeeid bigint, IN employeetitle text, IN employeeaddress text)
  RETURNS bigint
  LANGUAGE 'plpgsql'
  
  AS $BODY$
  BEGIN
  DECLARE affectedrecordid bigint = 0
  IF employeeid = 0 THEN
  INSERT INTO employeemaster(title, address)
  values(employeetitle, employeeaddress)
  RETURNING id INTO affectedrecordid;
  RETURN affectedrecordid;
  ELSE
  UPDATE employeemaster 
  SET title = employeetitle,
  address = employeeaddress
  WHERE id = employeeid  
  RETURN employeeid;
  END IF
  END
  $BODY$;
  </code></pre>
  
  <p>When I execute the above statement I am getting the following error:</p>
  
  <pre><code>ERROR:  syntax error at or near "IF"
  LINE 8: IF employeeid = 0 THEN
          ^
  SQL state: 42601
  Character: 218
  </code></pre>
  
  <p>I am unable to figure out the issue. Can someone help me fixing the above function?</p>