+
+-- get_minmax_score_for_players(tournament, playmode)
+CREATE TYPE minmax_rank_entire_tournament AS (
+ round INTEGER,
+ parallel INTEGER,
+ player INTEGER,
+ best_rank INTEGER,
+ worst_rank INTEGER
+);
+CREATE FUNCTION get_minmax_rank_for_players(integer, varchar) RETURNS SETOF minmax_rank_entire_tournament
+ AS $$
+DECLARE
+ ret minmax_rank_entire_tournament;
+ tr record;
+ tp record;
+BEGIN
+ FOR tr IN SELECT * FROM groups WHERE tournament=$1 LOOP
+ ret.round = tr.round;
+ ret.parallel = tr.parallel;
+
+ FOR tp IN SELECT * FROM get_minmax_rank_for_players($1, tr.round, tr.parallel, $2) LOOP
+ ret.player = tp.player;
+ ret.best_rank = tp.best_rank;
+ ret.worst_rank = tp.worst_rank;
+ RETURN NEXT ret;
+ END LOOP;
+ END LOOP;
+ RETURN;
+END;
+ $$
+ LANGUAGE plpgsql
+ STABLE
+ RETURNS NULL ON NULL INPUT;