title: PostgreSQL crosstab/pivot problems
body: <p>I have a <code>prefs</code> table, and here are the relevant columns:</p>
  
  <pre><code>mydb=&gt; SELECT pref_id, pref_name, pref_value FROM prefs;
   pref_id |  pref_name   |   pref_value
  ---------+--------------+----------------
         1 | PagerNumber  | 2125551234
         2 | PagerCarrier | @att.com
         3 | PagerCarrier | @something.com
  </code></pre>
  
  <p>I want to produce something like this:</p>
  
  <pre><code> section |  pager_number  | pager_carrier
  ---------+----------------+---------------
         1 | 2125551234     |
         2 |                | @att.com
         3 |                | @something.com
  </code></pre>
  
  <p>So I used crosstab, following this example on stackoverflow: <a href="https://stackoverflow.com/questions/3002499/postgresql-crosstab-query">PostgreSQL Crosstab Query</a></p>
  
  <pre><code>SELECT row_name AS section,
         category_1::text AS pager_number,
         category_2::text AS pager_carrier
  FROM crosstab('select pref_id::bigint, pref_name::text, pref_value::text
      FROM prefs')
  AS ct (row_name bigint, category_1 text, category_2 text);
  </code></pre>
  
  <p>All the values are going into <code>pager_number</code>, and <code>pager_carrier</code> is left empty:</p>
  
  <pre><code> section |  pager_number  | pager_carrier
  ---------+----------------+---------------
         1 | 2125551234     |
         2 | @att.com       |
         3 | @something.com |
  </code></pre>
  
  <p>Can anyone see what's going on?</p>