title: How to return number of rows deleted in postgresql function
body: <p>Here is a very simplified example of what I am trying to do. Consider this table of people:</p>
  
  <pre><code>CREATE TABLE people (pid SERIAL PRIMARY KEY, firstname TEXT, isalive BOOLEAN);
  
  INSERT INTO people (firstname, isalive) VALUES
      ('Sam', TRUE),
      ('Leslie', FALSE),
      ('Parker', FALSE);
  </code></pre>
  
  <p>Now I want to delete dead people from the table. When I do this in <code>psql</code>, I see a message telling me how many rows were deleted.</p>
  
  <pre><code>postgres=&gt; DELETE FROM people WHERE isalive = FALSE;
  DELETE 2
  postgres=&gt;
  </code></pre>
  
  <p>However, if I put this delete statement into a function and call it, I don't see the same message.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION deletedead() RETURNS void AS $$
    DELETE FROM people WHERE isalive = FALSE;
  $$ LANGUAGE SQL;
  
  SELECT deletedead();
  </code></pre>
  
  <p>This deletes the rows as expected, but it doesn't give any message saying how many rows were deleted. <strong>How do I get a message like "DELETE 2" from this function?</strong></p>
  
  <p>I tried modifying my function to return the number of rows deleted:</p>
  
  <pre><code>-- This doesn't work
  CREATE OR REPLACE FUNCTION deletedead() RETURNS int AS $$
    DELETE FROM people WHERE isalive = FALSE RETURNING COUNT(*);
  $$ LANGUAGE SQL;
  </code></pre>
  
  <p>... but I get an error saying <code>ERROR:  aggregate functions are not allowed in RETURNING</code></p>