Added a stored procedure for finding the min/max rank for an entire tournament.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jun 2005 00:31:46 +0000 (00:31 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jun 2005 00:31:46 +0000 (00:31 +0000)
sql/ccbs.sql

index cb440e8005016a1ebbf7f26025138fed90903f76..99b67003306220af9b40e6ce7234d0ede634c4e7 100644 (file)
@@ -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;