title: Postgres Check for Empty JSONB Fields
body: <p>I want to be able to <code>ignore</code> or prevent an <code>INSERT</code> from occurring if there is a JSON object with keys but no values from within a Postgres function.Here is a small, contrived example:</p>
  
  <pre><code>DROP TABLE IF EXISTS mytable;
  create table mytable(
  a text,
  b text
  );
  
  CREATE OR REPLACE FUNCTION insert_to_table(
  somedata JSONB
  )
  RETURNS VOID AS $$
  BEGIN 
  insert into mytable (a, b) select a,b from jsonb_populate_recordset(null::mytable, $1::jsonb);
  END;
  $$ LANGUAGE plpgsql;
  
  select insert_to_table('[{"a":1,"b":2},{"a":3,"b":4}, {"a":null, "b": null}, {"a": null, "b": "some data"}]');
  </code></pre>
  
  <p>This will insert 4 records, with the first row being <code>1,2</code> and the next row being <code>3,4</code>. The third row is <code>"", ""</code>, and the forth is <code>"", some data</code>. </p>
  
  <p>In this scenario, rows 1,2, and 4 are valid. I want to ignore 3 and prevent it from being inserted.</p>
  
  <p>I do not want a blank row, and my data/table will be much larger than what is listed (roughly 20 fields in the table, and 20 key/value pairs in the JSON).</p>
  
  <p>Most likely I will need to loop over the array and pick out <code>JSON</code> object where ALL the keys are null and not just 1 or 2.</p>
  
  <p>How can I do that? </p>