From: Steinar H. Gunderson Date: Sun, 12 Jun 2005 00:31:46 +0000 (+0000) Subject: Added a stored procedure for finding the min/max rank for an entire tournament. X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=4ef40bec0dfd1b5e01a79f6267cfc758be8ac939 Added a stored procedure for finding the min/max rank for an entire tournament. --- diff --git a/sql/ccbs.sql b/sql/ccbs.sql index cb440e8..99b6700 100644 --- a/sql/ccbs.sql +++ b/sql/ccbs.sql @@ -342,4 +342,36 @@ END; LANGUAGE plpgsql VOLATILE -- not really, but needed for the TEMPORARY TABLE RETURNS NULL ON NULL INPUT; - + +-- 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;