-- args file id
DROP FUNCTION update_account_votes(INT);
CREATE OR REPLACE FUNCTION update_account_votes(INT) RETURNS REAL
AS $$
  # updating accountvoteavg column
  set_accavg = plpy.prepare("UPDATE account SET avgfilevote = (SELECT avg(voteavg) FROM file WHERE file.setupaccountid = $1) WHERE accountid = $2 RETURNING avgfilevote", ["int", "int"])
  avgs = plpy.execute(set_accavg, [args[0], args[0]])

  return avgs[0]["avgfilevote"]
$$ LANGUAGE plpython3u;
