I need to perform multiple table inserts, where the last table relies on the one before it and includes an additional list of items. I am working with pg in conjunction with node.js and JavaScript.
Table 1:
insert into col1, col2 values (1, 2) return col1 as table1_id
Table 2:
insert into col1 col2 values (table1_id, val1), (table1_id, val2), ... (table1_id, val_n)
I have observed examples where this has been done with just a single row in the final table. In my case, however, I will have a list of items from val1 to valn that need to be associated with the ID generated from the initial insert in Table 1 and then added to a pre-existing list. The goal is to create a relationship table containing a range of items tied to a record in Table 1.
If anyone has any insights or advice, it would be greatly appreciated.
Thank you