myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

03-score-summary-function.sql (555B)


      1 -- remove the old view
      2 drop view if exists score_summary;
      3 
      4 -- create new function with input parameter "publicOnly"
      5 create or replace function score_summary(publicOnly boolean)
      6 returns table(athlete_id bigint, heat_id bigint, score_summary double precision)
      7 language plpgsql
      8 set search_path = ''
      9 as $$
     10 begin
     11   return query
     12   select a.id, s.heat, SUM(s.score)
     13   from public.scores s
     14   join public.athletes as a on a.id = s.athlete
     15   join public.heats as h on s.heat = h.id
     16   where (publicOnly = false or h.private = false)
     17   group by a.id, s.heat;
     18 end;
     19 $$;