title: Postgres trigger works for INSERT, not for DELETE
body: <p>I am having a problem with a trigger. I created a trigger and a function to keep track of how many rows are in use by each user in my DB. The INSERT part of the trigger and function work correctly, but the DELETE does nothing. When I insert rows in my app, the rowcount goes up, when I delete, the rowcount does not change. </p>
  
  <p>Here is the TABLE where I keep the row count:</p>
  
  <pre><code>Table "public.rowcount"
     Column   |  Type   | Modifiers 
  ------------+---------+-----------
   user__id   | integer | not null
   table_name | text    | not null
   total_rows | bigint  | 
  </code></pre>
  
  <p>Here is my TRIGGER:</p>
  
  <pre><code>CREATE TRIGGER countrows_m_time
    AFTER INSERT OR DELETE on m_time
    FOR EACH ROW EXECUTE PROCEDURE count_rows_m_time();
  </code></pre>
  
  <p>And here is the FUNCTION:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION count_rows_m_time()
  RETURNS TRIGGER AS
  '  
     BEGIN
        IF TG_OP = ''INSERT'' THEN
          UPDATE rowcount
            SET total_rows = total_rows + 1
            WHERE table_name = TG_RELNAME
            AND user__id = (SELECT user__id from vi_m_time_users where m_value_id = NEW.m_value_id);
        ELSIF TG_OP = ''DELETE'' THEN
           UPDATE rowcount
              SET total_rows = total_rows - 1
              WHERE table_name = TG_RELNAME
              AND user__id = (SELECT user__id from vi_m_time_users where m_value_id = OLD.m_value_id);
        END IF;
        RETURN NULL;
     END;
  ' LANGUAGE plpgsql;
  </code></pre>
  
  <p>Any ideas?
  Many thanks,
  Shea</p>