title: Postgresql query dictionary of objects in JSONB field
body: <p>I have a table in a PostgreSQL 9.5 database with a JSONB field that contains a dictionary in the following form:</p>
  
  <pre><code>{'1': {'id': 1,
         'length': 24,
         'date_started': '2015-08-25'},
   '2': {'id': 2,
         'length': 27,
         'date_started': '2015-09-18'},
   '3': {'id': 3,
         'length': 27,
         'date_started': '2015-10-15'},
  }
  </code></pre>
  
  <p>The number of elements in the dictionary (the '1', '2', etc.) may vary between rows. </p>
  
  <p>I would like to be able to get the average of <code>length</code> using a single SQL query. Any suggestions on how to achieve this ?</p>