Check my function?
# help-and-questions
d
table.grammar_count has one row, two columns id (int2 primary) total (int4) table.grammar_stats is getting updated via the JS library v2: id (uuid) char_count (int2) My trigger seems to be firing, but the table.grammar_count is not updating. Any pointers would be appreciated. Thanks.
Copy code
CREATE OR REPLACE FUNCTION update_grammar_count()
RETURNS TRIGGER AS $$
BEGIN
  UPDATE grammar_count
  SET total = total + NEW.char_count
  WHERE id = 1;

  INSERT INTO custom_logs (message)
  VALUES('Trigger update_grammar_count fired');

  RETURN NEW;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS grammar_count_insert_trigger ON grammar_stats;

CREATE TRIGGER grammar_count_insert_trigger
AFTER INSERT ON grammar_stats
FOR EACH ROW
EXECUTE FUNCTION update_grammar_count();