title: Calling function passing JSONB as parameter - Postgres
body: <p>Below is the function which I have written</p>
  <pre><code>     CREATE OR REPLACE FUNCTION upd.insert_testdata(spec jsonb[])
       RETURNS void
       LANGUAGE 'plpgsql' AS $BODY$
              
       BEGIN
      --Consider all columns in specialist table as character varying and code column as integer.
          insert into upd.specialist (to_cd, empid, code, booking_status, availability)
             select j.spec-&gt;&gt;'to_cd', 
                    j.spec-&gt;&gt;'empid', 
                    j.spec-&gt;&gt;'code', 
                    j.spec-&gt;&gt;'booking_status',
                    j.spec-&gt;&gt;'availability' 
             from jsonb_populate_record(spec) j;
          
                  
       END;
       $BODY$;
  </code></pre>
  <p>I am trying to call function by following command</p>
  <pre><code>    SELECT upd.insert_testdata(
                 '{
                  &quot;to_cd&quot;:&quot;NFG&quot;,
                  &quot;empid&quot;:&quot;test&quot;,
                  &quot;code&quot;:123,
                  &quot;booking_status&quot;:&quot;Y&quot;, 
                  &quot;availability&quot;:&quot;MTWTFSS&quot;
                   }'::jsonb[]
               );
  </code></pre>
  <p>But I am getting error as <strong>Malformed array Literal</strong></p>
  <p><strong>DETAIL:  Unexpected array element.</strong>
  <strong>SQL state: 22P02</strong></p>
  <p>Also I would like to know how to insert multiple records/pass multiple rows in single json variable</p>