In this sql statement
INSERT INTO child (parentId, value) SELECT parentId, value FROM temptable
child.parentId is a foreign key pointing to parent.id. Rows in the parent table might be deleted at any time while this long-running INSERT INTO statement (that could insert up to a few million rows) is running.
If the child table has no corresponding foreign key in parent before the INSERT INTO statement begins running, or if a row in the parent table referenced from child was deleted while this INSERT INTO is running, I'd like the INSERT INTO to silently ignore that particular row (and simply skip inserting into child the rows that violate the foreign key constraint) rather than the whole statement failing.
How can I accomplish this? I'm not familiar with how any race conditions would work in this case.