title: SQL Function: "Query Has No Destination for Result Data"
body: <p>I'm working on what shouldn't be too difficult an SQL function: it takes a few parameters to find a specific course in a table, counts how many people are in that course, compares it to the course's maximum capacity, and returns 1 or 0 as appropriate:</p>
  
  <pre><code>drop function if exists room_for_more_students(the_class_name varchar, the_semester_code int);
  create function room_for_more_students(the_class_name varchar, the_semester_code int) 
  returns int as $BODY$
  begin
      select * from class_offerings as match_table 
      where class_name = the_class_name and semester_code = the_semester_code;
      select count(student_id) from match_table as num_students_in_class;
      select avg(maximum_capacity) from match_table as num_students_allowed_in_class;
      --These will all be the same so "avg" just means "the maximum capacity for the class"
      if  num_students_in_class &lt; num_students_allowed_in_class then return 1;
      else return 0;
      end if;
  end
  $BODY$
  language plpgsql;
  </code></pre>
  
  <p>This doesn't really seem like it should be all that complex to implement, and the function creates without issue, but every time I try and invoke it through psycopg2 I receive:</p>
  
  <pre><code>ProgrammingError: query has no destination for result data
  HINT: If you want to discard the results of a SELECT, use PERFORM instead
  </code></pre>
  
  <p>I have tried experimenting with PERFORM instead, but any combination I try seems to either keep the same issue or create a host of new ones. I've also done some research on this as there are a few other posts about the same issue, but the majority of the time the answer seems to be that the user hasn't added specific return statements, which I have. I'm completely out of ideas and would appreciate any input possible.</p>