title: SELECT distinct gives wrong count
body: <p>I've got a problem where my <code>count(*)</code> will return the number of rows before distinct rows are filtered.</p>
  
  <p>This is a simplified version of my query. Note that I'll extract a lot of other data from the tables, so <code>group by</code> won't return the same result, as I'd have to group by maybe 10 columns. The way it works is that <code>m</code> is a map mapping <code>q</code>, <code>c</code> and <code>kl</code>, so there can be several references to <code>q.id</code>. I only want one.</p>
  
  <pre><code>SELECT distinct on (q.id) count(*) over() as full_count
  from q, c, kl, m 
  where c.id = m.chapter_id
      and q.id = m.question_id
      and q.active = 1
      and c.class_id = m.class_id
      and kl.id = m.class_id
  order by q.id asc
  </code></pre>
  
  <p>If I run this i get <code>full_count = 11210</code> while it only returns 9137 rows. If I run it without the <code>distinct on (q.id)</code>, distinct on (q.id) is indeed the number of rows.</p>
  
  <p>So it seems that the count function doesn't have access to the filtered rows. How can I solve this? Do I need to rethink my approach?</p>