title: How can I append a given key to a PostgreSQL JSONB array?
body: <p>I have a JSONB store. </p>
  
  <pre><code>requests: {
   "0000": ["1111"],
   "1111": ["2222"]
  }
  </code></pre>
  
  <p>I can add into the store just fine when I have an initial value with:</p>
  
  <pre><code>UPDATE users SET requests = jsonb_insert(requests::jsonb, '{2222}', $$["3333"]$$);
  </code></pre>
  
  <p>However if I need to append to the array, it acts like I'm trying to replace the value and throws:</p>
  
  <pre><code>UPDATE users SET requests = jsonb_insert(requests::jsonb, '{0000}', $$["4444"]$$);
  ERROR:  cannot replace existing key
  HINT:  Try using the function jsonb_set to replace key value.
  </code></pre>
  
  <p>Desired output would be:</p>
  
  <pre><code>requests: {
   "0000": ["1111", "4444"],
   "1111": ["2222"]
  }
  </code></pre>
  
  <p>Seems I'm missing a simple <code>array_append</code> or something but can't manage to figure it out.</p>