create or replace function subject_f(integer) returns setof subject as $$ select * from subject s where not exists(select * from assign where (s_code, e_code) = (s.code, $1)) order by s.code ; $$ language sql;