title: Hot to use results from procedure calls as conditions
body: <p>I have a procedure that checks for a condition (if a session is fully booked). I want to make a trigger that checks if the session is fully booked before inserting a new booking.</p>
  
  <p>What I imagine it would be like is something like this.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION check_if_session_is_full_trigger()
     RETURNS trigger AS
  $BODY$
  BEGIN
       IF (EXECUTE session_is_full(NEW.session_id)) THEN
           RAISE EXCEPTION 'SESSION IS FULLY BOOKED';
      RETURN NEW;
  END;
  $BODY$
     LANGUAGE plpgsql; 
  </code></pre>
  
  <p>But I get this </p>
  
  <pre><code>ERROR:  syntax error at or near "session_is_full"
  LINE 5:      IF (EXECUTE session_is_full(NEW.session_id) = TRUE) THE...
  </code></pre>
  
  <p>So obviously I'm not doing something right.</p>
  
  <p>session_is_full(int) returns boolean.</p>
  
  <p>Am I on the right track, and how to fix this?</p>