title: PostgreSQL: Combine Count and DISTINCT ON
body: <p>Given this table</p>
  
  <pre><code>| id | name  | created_at                 |
  | 1  | test  | 2015-02-24 11:13:28.605968 |
  | 2  | other | 2015-02-24 13:04:56.968004 |
  | 3  | test  | 2015-02-24 11:14:24.670765 |
  | 4  | test  | 2015-02-24 11:15:05.293904 |
  </code></pre>
  
  <p>And this query which returns only the rows id 2 and id 4.</p>
  
  <pre><code>SELECT DISTINCT ON (documents.name) documents.*
  FROM "documents"  
  ORDER BY documents.name, documents.created_at DESC
  </code></pre>
  
  <p>How can i return the number of rows affected? Something like</p>
  
  <pre><code>SELECT COUNT(DISTINCT ON (documents.name) documents.*) FROM "documents"
  </code></pre>