title: Updating integer column from jsonb member fails with: column is of type integer but expression is of type jsonb
body: <p>In a PostgreSQL 9.5 table I have an <code>integer</code> column <code>social</code>.</p>
  
  <p>When I try to update it in a stored procedure given the following JSON data (an array with 2 objects, each having a "social" key) in the <code>in_users</code> variable of type <code>jsonb</code>:</p>
  
  <blockquote>
  <pre><code>'[{"sid":"12345284239407942","auth":"ddddc1808197a1161bc22dc307accccc",**"social":3**,"given":"Alexander1","family":"Farber","photo":"https:\/\/graph.facebook.com\/1015428423940942\/picture?type=large","place":"Bochum,
  Germany","female":0,"stamp":1450102770},
    {"sid":"54321284239407942","auth":"ddddc1808197a1161bc22dc307abbbbb",**"social":4**,"given":"Alxander2","family":"Farber","photo":null,"place":"Bochum,
  Germany","female":0,"stamp":1450102800}]'::jsonb
  </code></pre>
  </blockquote>
  
  <p>Then the following code is failing:</p>
  
  <pre><code>    FOR t IN SELECT * FROM JSONB_ARRAY_ELEMENTS(in_users)
      LOOP
              UPDATE words_social SET
                      social = t-&gt;'social',
              WHERE sid = t-&gt;&gt;'sid';
      END LOOP;
  </code></pre>
  
  <p>with the error message:</p>
  
  <pre><code>ERROR:  column "social" is of type integer but expression is of type jsonb
  LINE 3:                         social = t-&gt;'social',
                                           ^
  HINT:  You will need to rewrite or cast the expression.
  </code></pre>
  
  <p>I have tried changing that line to:</p>
  
  <pre><code>social = t-&gt;'social'::int,
  </code></pre>
  
  <p>but then I get the error:</p>
  
  <pre><code>ERROR:  invalid input syntax for integer: "social"
  LINE 3:                         social = t-&gt;'social'::int,
                                              ^
  </code></pre>
  
  <p>Why doesn't PostgreSQL recognize that the data is <code>integer</code>?</p>
  
  <p>From the <a href="http://www.postgresql.org/docs/9.5/static/datatype-json.html#JSON-TYPE-MAPPING-TABLE" rel="nofollow">JSON-TYPE-MAPPING-TABLE</a> I was having the impression that JSON number would be auto-converted to PostgreSQL numeric type.</p>