From: Steinar H. Gunderson Date: Sun, 12 Jun 2005 00:10:55 +0000 (+0000) Subject: Make the rank function work more than once. :-) X-Git-Url: https://git.sesse.net/?p=ccbs;a=commitdiff_plain;h=e94a90a317b44352b4e282a9ce6290e698ef87ff Make the rank function work more than once. :-) --- diff --git a/sql/ccbs.sql b/sql/ccbs.sql index ab682cd..6a96a20 100644 --- a/sql/ccbs.sql +++ b/sql/ccbs.sql @@ -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; $$