title: Storing up to the most recent N elements in a Postgres jsonb field
body: <p>I have a Postgres table with a JSONB column in which I want to store an array. The array starts off having 0 elements but will grow to hold up to N elements.</p>
  <p>With every update I need to append one element to this field until the number of elements has grown from 0 to N. After that every time a new element is added the oldest one should be dropped such that the array only holds the most recent N elements.</p>
  <p>So if the table is <strong>myTable</strong>, the JSONB array column is <strong>myArray</strong>, the incoming element is <strong>myElement</strong> and N is 10, I would have...</p>
  <pre><code>UPDATE myTable SET myArray=???
  </code></pre>
  <p>Can anyone provide the query that would append elements in this way?</p>
  <p>Thanks in advance!</p>