title: pivot/cross distinct row data to colums with postgres
body: <p>I have distinct data that I want to pivot/cross, for instance</p>
  
  <p>Given table A with</p>
  
  <pre><code>name  tag
  Bob   sport
  Bob   action
  Bob   comedy
  Tom   action
  Tom   drama
  Sue   sport
  </code></pre>
  
  <p>I'd like a query that transforms the data to</p>
  
  <pre><code>name  sport  action  comedy  drama
  Bob   1      1       1       0
  Tom   0      1       0       1
  Sue   1      0       0       0
  </code></pre>
  
  <p>For any number n of distinct tags. </p>
  
  <p>How would I create this transformation using sql if I didn't know the distinct tags before I begin.</p>