Again, ask Postgres. Extending on the procedure for your previous question:
CREATE TEMP TABLE pencil_count (
pencil_color varchar(30)
, count integer
);
CREATE TABLE pencil_count_with_date (
date_ date
, pencil_count pencil_count[]
);
CREATE TABLE pencils (
id serial
, pencils_ pencil_count_with_date[]
);
Ask Postgres for each nested level:
INSERT INTO pencil_count VALUES ('red' , 1), ('blue', 2);
SELECT ARRAY(SELECT p FROM pencil_count p)::text AS p_row_arr;
-- with result from above:
INSERT INTO pencil_count_with_date(date_, pencil_count)
VALUES ('2016-04-14', '{"(red,1)","(blue,2)"}')
, ('2016-04-14', '{"(red,3)","(blue,4)"}');
SELECT ARRAY(SELECT p FROM pencil_count_with_date p)::text AS p2_row_arr;
-- with result from above:
INSERT INTO pencils(pencils_)
VALUES
('{"(2016-04-14,\"{\"\"(red,1)\"\",\"\"(blue,2)\"\"}\")"
,"(2016-04-15,\"{\"\"(red,3)\"\",\"\"(blue,4)\"\"}\")"}');
SELECT id, pencils_::text FROM pencils;
Result:
id | pencils_
---+-------------------------------------------------------
1 | {"(2016-04-14,\"{\"\"(red,1)\"\",\"\"(blue,2)\"\"}\")"
,"(2016-04-15,\"{\"\"(red,3)\"\",\"\"(blue,4)\"\"}\")"}
fiddle
Old sqlfiddle
I fully agree with advice so far: Multiple levels of nested row types is typically complex and inefficient. Consider normalization.
More in my answer to your previous question:
;to your first two commands. DDL needs semicolons, too ...array[...], that makes everything so much easier. (2) Isn't this the same thing as your other question recent question?