title: Can get an average of values in a json array using postgres?
body: <p>One of the great things about postgres is that it <a href="http://www.postgresql.org/docs/9.3/static/functions-json.html" rel="nofollow">allows indexing into a json object</a>.</p>
  
  <p>I have a column of data formatted a little bit like this:</p>
  
  <pre><code>{"Items":
    [
      {"RetailPrice":6.1,"EffectivePrice":0,"Multiplier":1,"ItemId":"53636"},
      {"RetailPrice":0.47,"EffectivePrice":0,"Multiplier":1,"ItemId":"53404"}
    ]
  }
  </code></pre>
  
  <p>What I'd like to do is find the average RetailPrice of each row with these data.</p>
  
  <p>Something like </p>
  
  <pre><code>select avg(json_extract_path_text(item_json, 'RetailPrice')) 
  </code></pre>
  
  <p>but really I need to do this for each item in the items json object. So for this example, the value in the queried cell would be 3.285</p>
  
  <p>How can I do this?</p>