title: How to get elements with a unique number from a json array in PostgreSQL?
body: <p>I have a table <code>bank_accounts</code>:</p>
  
  <pre><code>    Column     |         Type          |                                Modifiers                                | Storage  | Stats target | Description 
  ---------------+-----------------------+-------------------------------------------------------------------------+----------+--------------+-------------
   id            | integer               | not null default nextval('bank_accounts_id_seq'::regclass)              | plain    |              | 
   name          | character varying(50) |                                                                         | extended |              | 
   bank_accounts | jsonb                 | not null                                                                | extended |              | 
  </code></pre>
  
  <p>And it has some JSON in the <code>jsonb</code> column:</p>
  
  <pre><code> id | name  |                              bank_accounts                               
  ----+-------+--------------------------------------------------------------------------
    1 | test1 | [{"name": "acct1", "balance": -500}, {"name": "acct2", "balance": -300}]
  </code></pre>
  
  <p>And I am using jsonb_array_elements to get a list of the accounts for one user:</p>
  
  <pre><code>select jsonb_array_elements(bank_accounts)-&gt;&gt;'name' as name, jsonb_array_elements(bank_accounts)-&gt;&gt;'balance' as balance from bank_accounts;
   name  | balance 
  -------+---------
   acct1 | -500
   acct2 | -300
  </code></pre>
  
  <p>That's all great. But how do I get each row to have a unique id? I'd like to map each row to a hibernate object, but I'm having trouble doing that because I can't find a way to get each row to have a unique id.</p>