简体   繁体   English

插入10条不冲突的记录

[英]Insert 10 records that don't conflict

If I want to insert 10 records from table_a to table_b I can do this:如果我想将 10 条记录从table_a插入到table_b我可以这样做:

insert into table_b
select * from table_a
limit 10

Now lets set I want to insert 10 records from table_a to table_b that don't conflict how do I do it?现在让我们设置我想从table_a插入 10 条不冲突的记录到table_b我该怎么做?

If I do this:如果我这样做:

insert into table_b
select * from table_a
limit 10
on conflict do nothing

Then 10 records won't be inserted.然后不会插入 10 条记录。 If any of those first 10 records conflict then it wont keep going to fully insert 10 records.如果前 10 条记录中的任何一条发生冲突,那么它将不会继续完全插入 10 条记录。 It will be 10 minus conflicts which could be 0.这将是 10 减去可能是 0 的冲突。

How do I insert 10 non-conflicting records?如何插入 10 条不冲突的记录?

Insert from a query that makes sure the records do not exist in table_b :从确保记录不存在于table_b的查询中插入:

insert into table_b
select * from table_a
except
select * from table_b
limit 10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM