I have defined two tables, scores and analyzed_avg_score, in my postgres database. I also have a function which i declaired like that:
CREATE FUNCTION updateAvgScore() RETURNS void AS $$
INSERT into analyzed_avg_score
(SELECT
user,
avg(score_value)
FROM
scores
group by user) on conflict do nothing;
$$ LANGUAGE SQL;
Now, I want to have a trigger or something similar that runs this function every time I insert or update something in score. I don't have a lot of experience with SQL, yet. So, does anyone have an idea how the trigger should look like?
analyzed_avg_scorewhen the user already exists instead of doing nothing.