I have the following array:
arr = [{"a":1, "b": 2}, {"a": 1, "b": 3}]
Using some help from this post, I am trying to parse these elements like this:
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;
This returns:
"{{""a"": 1, ""b"": 2},{""a"": 1, ""b"": 3}}"
Now I want to insert these values into a table, couple with 2 fkeys with each row insert:
FOR LOOP OVER ARR:
INSERT INTO table VALUES (DEFAULT, somefkeyvalue, arr[i].a, arr[i].b);
How would I go about writing the above query to the real thing?