title: Get a json attribute with variable name in Postgres
body: <p>not an SQL guru here.
  Trying to write a query that gets a few columns of a table, and only the value &quot;icon&quot; of the json column below (named weather). I got to a pointwhere i can list all the attributes listed right after sessions, which are timestamps, but no luck in iterating them and joining to the rest of the table.
  I also have the feeling that it wasn't very clever to store that value as an attribute name, especially as it's already stored in the &quot;dt&quot; value.</p>
  <p>Can anybody confirm if this is best practice or not?
  And could somebody help me get the &quot;icon&quot; value?</p>
  <pre><code>{
     &quot;lat&quot;:43.6423,
     &quot;lon&quot;:-72.2518,
     &quot;timezone&quot;:&quot;America/New_York&quot;,
     &quot;timezone_offset&quot;:-14400,
     &quot;sessions&quot;:{
        &quot;1651078174&quot;:{
           &quot;dt&quot;:1651078174,
           &quot;sunrise&quot;:1651052825,
           &quot;sunset&quot;:1651103155,
           &quot;temp&quot;:48.45,
           &quot;feels_like&quot;:43.63,
           &quot;pressure&quot;:1009,
           &quot;humidity&quot;:68,
           &quot;dew_point&quot;:38.39,
           &quot;uvi&quot;:5,
           &quot;clouds&quot;:100,
           &quot;visibility&quot;:10000,
           &quot;wind_speed&quot;:11.5,
           &quot;wind_deg&quot;:310,
           &quot;weather&quot;:[
              {
                 &quot;id&quot;:804,
                 &quot;main&quot;:&quot;Clouds&quot;,
                 &quot;description&quot;:&quot;overcast clouds&quot;,
                 &quot;icon&quot;:&quot;04d&quot;
              }
           ]
        }
     }
  }
  </code></pre>