Below is the function which I have written
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->>'to_cd',
j.spec->>'empid',
j.spec->>'code',
j.spec->>'booking_status',
j.spec->>'availability'
from jsonb_populate_record(spec) j;
END;
$BODY$;
I am trying to call function by following command
SELECT upd.insert_testdata(
'{
"to_cd":"NFG",
"empid":"test",
"code":123,
"booking_status":"Y",
"availability":"MTWTFSS"
}'::jsonb[]
);
But I am getting error as Malformed array Literal
DETAIL: Unexpected array element. SQL state: 22P02
Also I would like to know how to insert multiple records/pass multiple rows in single json variable