You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ibihf/migrations/20230406195131_create_tie_f...

20 lines
436 B

CREATE FUNCTION tie(game_id INT, team_id INT)
RETURNS INTEGER
AS $$
DECLARE
opponent_team_id INTEGER;
BEGIN
SELECT
teams.id
INTO
opponent_team_id
FROM games
JOIN teams
ON (teams.id=games.team_home
OR teams.id=games.team_away)
WHERE games.id=game_id
AND teams.id!=team_id;
RETURN (SELECT (CASE WHEN goals(game_id, team_id) = goals(game_id, opponent_team_id) THEN 1 ELSE 0 END));
END;
$$ LANGUAGE plpgsql;