title: PostgreSQL: Enumerate SQL query result
body: <p>Consider the following SQL query and response:</p>
  
  <pre><code>CREATE TEMPORARY TABLE dreams (name text, type text);
  INSERT INTO dreams VALUES ('Monkey', 'nice');
  INSERT INTO dreams VALUES ('Snake', 'Not nice');
  INSERT INTO dreams VALUES ('Donkey', 'nice');
  INSERT INTO dreams VALUES ('Bird', 'nice');
  
  SELECT name from dreams WHERE type='nice' ORDER BY name;
    name
  --------
   Bird
   Donkey
   Monkey
  (3 rows)
  </code></pre>
  
  <p>I would like to enumerate the results by the order of appearance, regardless of any existing ids, for convenience. The expected result should be something a-la:</p>
  
  <pre><code>SELECT &lt;magic_enumeration&gt;, name from dreams WHERE type='nice' ORDER BY name;
  
   magic_enumeration |  name
  -------------------+--------
   1                 | Bird
   2                 | Donkey
   3                 | Monkey
  (3 rows)    
  </code></pre>
  
  <p>Any ideas how to enumerate the query result by order of appearance?</p>