From: Ant Zucaro Date: Wed, 29 Feb 2012 12:05:05 +0000 (-0500) Subject: Function to merge two players. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b18626a94d1babcf4079f503c41cbafbb0106f41;p=xonotic%2Fxonstatdb.git Function to merge two players. --- diff --git a/functions/merge_players.sql b/functions/merge_players.sql new file mode 100644 index 0000000..0a77026 --- /dev/null +++ b/functions/merge_players.sql @@ -0,0 +1,34 @@ +create or replace function merge_players(p_winner_player_id players.player_id%TYPE, p_loser_player_id players.player_id%TYPE) RETURNS void as +$$ +declare + rowcount integer; +begin + -- start with weapon stats + update player_weapon_stats + set player_id = p_winner_player_id + where player_id = p_loser_player_id; + + get diagnostics rowcount = ROW_COUNT; + raise notice '% weapon stat rows updated.', rowcount; + + -- then game stats + update player_game_stats + set player_id = p_winner_player_id + where player_id = p_loser_player_id; + + get diagnostics rowcount = ROW_COUNT; + raise notice '% game stat rows updated.', rowcount; + + -- then hashkeys (winner takes the loser's hashkey) + update hashkeys + set player_id = p_winner_player_id + where player_id = p_loser_player_id; + + get diagnostics rowcount = ROW_COUNT; + raise notice '% hashkeys copied.', rowcount; + + -- and finally deactivate the old player record + update players set active_ind = false where player_id = p_loser_player_id; +end; +$$ +language plpgsql; \ No newline at end of file