0

I have two tables and a array of values to insert: table1 (id, name, createdAt, updatedAt) table2(id, name, table1Id)

Is there any way in postgresql or sequelize to make a bulkCreate, adding records in both tables and using the id generated in the insert of table1 as foreign key of the second table?

Rafael de Carvalho
  • 501
  • 1
  • 5
  • 10
  • https://stackoverflow.com/questions/2944297/postgresql-function-for-last-inserted-id – Salman A Dec 28 '21 at 13:30
  • You are missing significant necessary information. Take a few minuets to review [ask]. Specifically, update your question to include table definitions (ddl) and sample data (or even better a fiddle) and the expected results of that data. All as text - no images. – Belayer Dec 28 '21 at 19:10
  • You can use the `returning` command after the `insert` command. Example: `insert into table1 (name1, name2) values (pname1, pname2) returning id into p_id` – Ramin Faracov Jan 06 '22 at 03:23

0 Answers0