title: Transform table to one-hot-encoding of single column value
body: <p>I have a table with two columns:</p>
  
  <pre><code>+---------+--------+
  | keyword | color  |
  +---------+--------+
  | foo     | red    |
  | bar     | yellow |
  | fobar   | red    |
  | baz     | blue   |
  | bazbaz  | green  |
  +---------+--------+
  </code></pre>
  
  <p>I need to do some kind of one-hot encoding and transform table in PostgreSQL to:</p>
  
  <pre><code>+---------+-----+--------+-------+------+
  | keyword | red | yellow | green | blue |
  +---------+-----+--------+-------+------+
  | foo     |   1 |      0 |     0 |    0 |
  | bar     |   0 |      1 |     0 |    0 |
  | fobar   |   1 |      0 |     0 |    0 |
  | baz     |   0 |      0 |     0 |    1 |
  | bazbaz  |   0 |      0 |     1 |    0 |
  +---------+-----+--------+-------+------+
  </code></pre>
  
  <p>Is it possible to do with SQL only? Any tips on how to get started?</p>