在重复键上插入选择,忽略postgres

1N5*_*818 4 postgresql insert-select on-duplicate-key

我从这个来源读到,您可以在postgres中的dupcliate键ignore上进行插入,但是我似乎无法从以下选择中使用它:

链接

我已经看到您可以做的是:

insert into tab(id, val) values(1, 'nosert'), (2,
'nosert'), (3, 'nosert') on duplicate key ignore returning id;
Run Code Online (Sandbox Code Playgroud)

我为什么不能做这样的事情?

insert into table_one (field_one, field_two) select field_one, field_two from table_two on duplicate key ignore returning field_one;
Run Code Online (Sandbox Code Playgroud)

有人告诉我在重复项附近存在语法错误,但是在此之前的查询运行良好(尽管它在重复的索引上冲突),其余的查询只是添加on duplicate key ignore returning field_one

这不可能select from吗?

1N5*_*818 5

能够解决on conflict do nothing9.5

insert into table_one (field_one, field_two) 
select field_one, field_two from table_two 
on conflict do nothing;
Run Code Online (Sandbox Code Playgroud)