InsertId in one table and insert the same id with concat of array at the end in other table I have two tables namely orders and suborders.
table 1 - Order table
Columns - Order Id and qty
Table 2 - suborders
Column - SubId
Whenever a new order is placed the same id has to be inserted in the both table but in the table 2 would I like to generate a the subid as  same id+ with iteration of total number of qty .
Eg
Table1
Exak123 , 59 

I would like to get
Table 2
Exak123_1
Exak123_2 
..
.. 
Exak123_59
You can do this in a single statement using a data modifying CTE
with new_t1 as (
  insert into table_1 (order_id, qty)
  values ('Exak123', 59)
  returning *
)
insert into table_2 (sub_id)
select concat(t1.order_id, '_', g.nr)
from new_t1 t1
  cross join generate_series(1, t1.qty) as g(nr);