title: how to update jsonb value if path key is in variable postgresql
body: <p>I have a jsonb field in the table. I want to update an individual key value, So I am using jsonb_set method. The key that I want to update is in a variable.</p>
  
  <p>Here is the jsonb object that I want to update</p>
  
  <pre><code>{"yes":5,"total_votes":6,"no":1}
  </code></pre>
  
  <p>and the key variable <code>vote_to</code> is <code>yes</code>.</p>
  
  <p>Here is how I am trying</p>
  
  <pre><code>update polls set result = jsonb_set(result, ('{'||vote_to||'}'),vote_count::text::jsonb) where id=_poll_id;
  </code></pre>
  
  <p>And the error is </p>
  
  <pre><code>ERROR:  function jsonb_set(jsonb, text, jsonb) does not exist
  LINE 1: update polls set result = jsonb_set(result, ('{'||vote_to||'...
                                    ^
  HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
  </code></pre>
  
  <p>And how can I update two keys in one shot? And also <code>vote_count</code> is an integer so i need it to double cast to make <code>jsonb</code></p>
  
  <pre><code>vote_count::text::jsonb
  </code></pre>
  
  <p>Is there any other way to do this?</p>