title: FUNCTION syntax error
body: <pre><code>CREATE FUNCTION check_available_flightID(date)
  RETURNS integer AS 
  $$
  BEGIN 
    SELECT FlightID FROM Flight WHERE FlightDate::date = $1;
  
    IF NEW.FlightID IS NULL THEN 
    RAISE EXCEPTION 'No filight in the date you enter'
    END IF;
  
    RETURN query SELECT FlightID FROM Flight WHERE FlightDate::date = $1;
  $$
  LANGUAGE SQL;   
  </code></pre>
  
  <p>It said that the syntax error near "IF" ...
  A bit confused why some functions need the <code>BEGIN</code> and some do not.</p>
  
  <p>Can anyone please give me a hint?</p>