title: Set attribute value if correct type
body: <p>So I have a case where I need to set the value of an attribute depending on the type. To visualize a little bit, I have this table (lets call the table '<code>forecasts</code>'):</p>
  
  <pre><code>| creation_time | id |    d_type    |    d_amount  |
  |---------------|--- |--------------|--------------|
  |    1534842000 |  1 |           2  |          1.3 |
  |    1534842000 |  2 |           3  |          0.3 |
  </code></pre>
  
  <p>The <code>d_type</code> means which type it is, so for example, let's say:</p>
  
  <pre><code>1 = nothing
  2 = rain
  3 = snow
  </code></pre>
  
  <p>How could I get a table that looks something like:</p>
  
  <pre><code>| creation_time | id |    rain      |    snow      |
  |---------------|--- |--------------|--------------|
  |    1534842000 |  1 |          1.3 |            0 |
  |    1534842000 |  2 |            0 |          0.3 |
  </code></pre>
  
  <p>That is, the attribute should have a the value of <code>d_amount</code> if the attribute corresponds to the right <code>d_type</code>.</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>SELECT
          creation_time,
          id,
          "rain", CASE d_type WHEN 2 THEN d_amount END,
          "snow", CASE d_type WHEN 3 THEN d_amount END,
  FROM forecasts;
  </code></pre>
  
  <p>But it returns a case-column that I don't want. I'm new to PostgreSQL so sorry for noobing this down. Thankful for any help!</p>