Make the rank function work more than once. :-)
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jun 2005 00:10:55 +0000 (00:10 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 12 Jun 2005 00:10:55 +0000 (00:10 +0000)
sql/ccbs.sql

index ab682cd..6a96a20 100644 (file)
@@ -314,13 +314,20 @@ CREATE TYPE minmax_rank AS (
 );
 
 -- get_minmax_score_for_players(tournament, round, playmode)
+CREATE TABLE temp_minmax (
+       player INTEGER,
+       min_score INTEGER,
+       max_score INTEGER
+);
+
 CREATE FUNCTION get_minmax_rank_for_players(integer, integer, varchar) RETURNS SETOF minmax_rank
     AS $$
 DECLARE
        ret minmax_rank;
        tp RECORD;
 BEGIN
-       CREATE TEMPORARY TABLE temp_minmax AS SELECT * FROM get_minmax_score_for_players($1, $2, $3);
+       INSERT INTO temp_minmax SELECT * FROM get_minmax_score_for_players($1, $2, $3);
+       
        FOR tp IN SELECT * FROM temp_minmax LOOP
                ret.player = tp.player;
                ret.best_rank = 1 + ( SELECT COUNT(*) FROM temp_minmax WHERE min_score >= tp.max_score AND player<>tp.player);
@@ -328,7 +335,7 @@ BEGIN
 
                RETURN NEXT ret;
        END LOOP;
-       DROP TABLE temp_minmax; 
+       TRUNCATE temp_minmax;
        RETURN;
 END;
     $$