* fix discard scores
This commit is contained in:
parent
a75546a5be
commit
e63369d072
|
|
@ -214,3 +214,4 @@ fix_find_session_sorting_2216a.sql
|
|||
fix_find_session_sorting_2216b.sql
|
||||
fix_find_session_sorting_2216c.sql
|
||||
entabulate_current_network_scores.sql
|
||||
discard_scores_changed.sql
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
DROP FUNCTION IF EXISTS discard_scores();
|
||||
CREATE FUNCTION discard_scores () RETURNS VOID AS $$
|
||||
BEGIN
|
||||
WITH scores_to_delete AS (
|
||||
SELECT alocidispid, blocidispid, scorer, created_at FROM (SELECT *, row_number() OVER (PARTITION BY alocidispid, blocidispid, scorer ORDER BY scores.created_at DESC) AS rownum FROM scores) tmp WHERE rownum > 6
|
||||
)
|
||||
DELETE FROM scores USING scores_to_delete WHERE
|
||||
scores.alocidispid = scores_to_delete.alocidispid AND
|
||||
scores.blocidispid = scores_to_delete.blocidispid AND
|
||||
scores.scorer = scores_to_delete.scorer AND
|
||||
scores.created_at = scores_to_delete.created_at;
|
||||
RETURN;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
Loading…
Reference in New Issue