title: PostgreSql : Json Array to Rows using Lateral Join
body: <p>I have two following JSON Array in details field of my table and need to evaluate the query as I use in another relational table.</p>
  
  <pre><code>{
      "city": "London",
      "name": "Sainburry",
      "quantities": [112, 145, 222, 122, 124],
      "prices": [4, 4, 4, 0, 3],
      "dates": ["13.05.2020", "14.05.2020", "15.05.2020", "16.05.2020", "17.05.2020"]
  }
  </code></pre>
  
  <p>I want to evaluate the following query for this JSON Array:</p>
  
  <pre><code>select quantities,
         prices,
         AVG(quantities/prices::float) as ratio
  from my_table
  where city = 'London'
  group by quantities, prices;
  </code></pre>
  
  <p>I used the following query <strong>and many similar queries including lateral join</strong>:</p>
  
  <pre><code>select q.*
  from my_table mt
    cross join json_array_elements_text(details -&gt; 'quantities') as q
  </code></pre>
  
  <p>But, when adding the other fields (prices and dates) to the query by cross join, the rows multiplied. So, I am looking for a new feature <code>Lateral Join</code> to use, but not able to apply properly. How can I obtain the result I obtained previous query by using <code>Lateral Join</code> in PostgreSQL? Any help would be appreciated.</p>
  
  <p><strong><em>Update:</em></strong></p>
  
  <p>Here is the <a href="https://dbfiddle.uk/?rdbms=postgres_11&amp;fiddle=276a2cfc7cb591c8e189296968677252" rel="nofollow noreferrer">fiddle</a>. I can evaluate the desired result if I succeed to convert the json array values to rows without multiplying (5 records should be returned). Just help me to convert json array to row using <strong>lateral</strong> join and <strong>json_array_elements_text</strong>.</p>