title: How to calculate numbers nested in Postgresql JSON?
body: <p>I would like to do some operations with numbers stored in Postgresql 9.4 <code>JSON</code> format. Suppose I have this table:</p>
  
  <pre><code>CREATE TABLE t (id SERIAL, a JSON);
  
  INSERT INTO t (a)
  VALUES ('[[0.1, 2.0], [0.3, 4.0], [0.5, 6.0]]'),
         ('[[0.7, 8.0], [0.9, 10.0]]');
  </code></pre>
  
  <p>So I can decompose that with e.g. <code>json_array_elements()</code>:</p>
  
  <pre><code>SELECT id, json_array_elements(a) AS sub1 FROM t;
  
  id |   sub1
  ----------------
   1 | [0.1, 2.0]
   1 | [0.3, 4.0]
   1 | [0.5, 6.0]
   2 | [0.7, 8.0]
   2 | [0.9, 10.0]
  </code></pre>
  
  <p>Note, that the number of elements may vary. Now I would like to do some calculations with the sub-elements, like:</p>
  
  <pre><code>SELECT id,
         ((json_array_elements(a)-&gt;&gt;0)::FLOAT) *
         ((json_array_elements(a)-&gt;&gt;1)::FLOAT) as result
  FROM t
  </code></pre>
  
  <p>However I get the error: <code>ERROR: functions and operators can take at most one set argument</code>. Any hints?</p>