title: How to update a value based on key in json array in postgres?
body: <p>In a table there is a column data(jsonb)
  and json array like this</p>
  <pre class="lang-json prettyprint-override"><code>[
    {&quot;pid&quot;: &quot;123&quot;, &quot;percentage&quot;: &quot;10&quot;}, 
    {&quot;pid&quot;: &quot;456&quot;, &quot;percentage&quot;: &quot;50&quot;}, 
    {&quot;pid&quot;: &quot;789&quot;, &quot;percentage&quot;: &quot;40&quot;}
  ]
  </code></pre>
  <p>I want to update percentage 30 where pid is 789.
  I used this query but not succeeded.</p>
  <pre><code>UPDATE table
  SET data =
  jsonb_set(data, '{pid}'::text[], data-&gt;'pid' || '{&quot;percentage&quot;:&quot;30&quot;}'::jsonb)
  WHERE (data-&gt;&gt; 'pid') = '789' and id= '1'; [id is table's primary key]
  </code></pre>