title: Variable containing the number of rows affected by previous DELETE? (in a function)
body: <p>I have a function that is used as an INSERT trigger. This function deletes rows that would conflict with [the serial number in] the row being inserted. It works beautifully, so I'd really rather not debate the merits of the concept.</p>
  
  <pre><code>DECLARE
  re1 feeds_item.shareurl%TYPE;
  BEGIN
  SELECT regexp_replace(NEW.shareurl, '/[^/]+(-[0-9]+\.html)$','/[^/]+\\1') INTO re1;
  RAISE NOTICE 'DELETEing rows from feeds_item where shareurl ~ ''%''', re1;
  
  DELETE FROM feeds_item where shareurl ~ re1;
  RETURN NEW;
  END;
  </code></pre>
  
  <p>I would like to add to the NOTICE an indication of how many rows are affected (aka: deleted). How can I do that (using LANGUAGE 'plpgsql')?</p>
  
  <p><strong>UPDATE:</strong>
  Base on some excellent guidance from "Chicken in the kitchen", I have changed it to this:</p>
  
  <pre><code>DECLARE
  re1 feeds_item.shareurl%TYPE;
  num_rows int;
  BEGIN
  SELECT regexp_replace(NEW.shareurl, '/[^/]+(-[0-9]+\.html)$','/[^/]+\\1') INTO re1;
  
  DELETE FROM feeds_item where shareurl ~ re1;
  IF FOUND THEN
      GET DIAGNOSTICS num_rows = ROW_COUNT;
      RAISE NOTICE 'DELETEd % row(s) from feeds_item where shareurl ~ ''%''', num_rows, re1;
  END IF;
  RETURN NEW;
  END;
  </code></pre>