Sql 基于上一次插入插入插入多行
我想在表a中插入多行,并使用这些创建行的id在桥接表B中插入多行,每个id有两个条目Sql 基于上一次插入插入插入多行,sql,postgresql,insert,amazon-rds,postgresql-9.5,Sql,Postgresql,Insert,Amazon Rds,Postgresql 9.5,我想在表a中插入多行,并使用这些创建行的id在桥接表B中插入多行,每个id有两个条目 基本上,表B中A中创建的每一行应该有两行。您可以使用CTE,并使用returning子句: with i as ( insert into a ( . . . ) . . . returning * ) insert into bridge (a_id, other_id) select i.id, v.other_id from
基本上,表B中A中创建的每一行应该有两行。您可以使用CTE,并使用
returning
子句:
with i as (
insert into a ( . . . )
. . .
returning *
)
insert into bridge (a_id, other_id)
select i.id, v.other_id
from i cross join
(values ('x'), ('y')) v(other_id);