title: PostgreSQL - How to select the first consecutive group having same value
body: <p>I have a table with <code>pk</code> and <code>dept</code> columns:</p>
  
  <pre><code>pk dept
  -------
  27  A
  29  A
  30  B
  31  B
  33  A
  </code></pre>
  
  <p>I need to select the <strong>first consecutive group</strong>, that is the first successive set of rows all having the same <code>dept</code> value when the table is ordered by <code>pk</code>, i.e. the expected result is:</p>
  
  <pre><code>pk dept
  -------
  27  A
  29  A
  </code></pre>
  
  <p>In my example there are 3 consecutive groups (AA, BB and A). The size of a group is unlimited (can be more than 2).</p>