title: insert array of objects into table
body: <p>I have the following array:</p>
  
  <pre><code>arr = [{"a":1, "b": 2}, {"a": 1, "b": 3}]
  </code></pre>
  
  <p>Using some help from <a href="https://dba.stackexchange.com/questions/54283/how-to-turn-json-array-into-postgres-array">this post</a>, I am trying to parse these elements like this:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION jsonb_arr2text_arr(_js JSONB)
    RETURNS text[] AS
    $func$
  SELECT ARRAY(SELECT jsonb_array_elements_text(_js));
  $func$
  LANGUAGE sql IMMUTABLE;
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>"{{""a"": 1, ""b"": 2},{""a"": 1, ""b"": 3}}"
  </code></pre>
  
  <p>Now I want to insert these values into a table, couple with 2 <code>fkeys</code> with each row insert:</p>
  
  <pre><code>FOR LOOP OVER ARR:
      INSERT INTO table VALUES (DEFAULT, somefkeyvalue, arr[i].a, arr[i].b);
  </code></pre>
  
  <p>How would I go about writing the above <code>query</code> to the real thing?</p>