title: How to add numbers to grouped rows in postgresql group by clause
body: <p>I have a PostgreSQL table, containing duplicate values in a text column. It looks like this:</p>
  
  <pre><code>gid, capt
  1, foo
  2, foo
  3, bar
  4, bar
  5, bar
  6, buz
  7, buz
  </code></pre>
  
  <p>I need to add a column with distinct numbers for each value in a group, so my table should look like this:</p>
  
  <pre><code>gid, capt, rnum
  1, foo, 1
  2, foo, 2
  3, bar, 1
  4, bar, 2
  5, bar, 3
  6, buz, 1
  7, buz, 2
  </code></pre>
  
  <p>It's a kind of a row number inside each group, always starting from 1. Can anyone please provide me with an appropriate SELECT statement? </p>