I've read from this source that you can do an insert on dupcliate key ignore in postgres, but I cannot seem to get this to work for a select from:
link
What I've seen you can do is:
insert into tab(id, val) values(1, 'nosert'), (2,
'nosert'), (3, 'nosert') on duplicate key ignore returning id;
Why can't I do something like this?
insert into table_one (field_one, field_two) select field_one, field_two from table_two on duplicate key ignore returning field_one;
I'm being told that I have syntax error near duplicate, but the query before then runs fine (although it colides on a duplicate index) and the rest of the query just adds the on duplicate key ignore returning field_one
.
Is this not possible with select from
?
Was able to resolve with on conflict do nothing
for 9.5
insert into table_one (field_one, field_two)
select field_one, field_two from table_two
on conflict do nothing;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With