I've seen a few posts about inserting into two tables with one query using CTEs. See Insert data in 3 tables at a time using Postgres
Is there a way to do so for data that contains an array to be unnested?
Example:
CREATE TABLE parent (
id serial PRIMARY KEY,
name text
);
CREATE TABLE child(
id serial PRIMARY KEY,
name text,
parent_id integer references parent
);
I'd like to insert my data, which is of the form
(parent_name, children_names) as (values (
('Parent1', ARRAY['Parent1-Child1', 'Parent1-Child2']),
('Parent2', ARRAY['Parent2-Child1']),
...,
))
For additional context> I insert one "superparent" at a time, which consists of multiple parents, so I'd like be able to insert multiple parents at the same time, as opposed to one parent at a time.