I have this simple setup
CREATE TABLE stop ( id INT UNIQUE, name TEXT, PRIMARY KEY(id) ); CREATE TABLE line ( id INT UNIQUE, name TEXT, PRIMARY KEY(id) ); CREATE TABLE line_stops_sequence( id SERIAL PRIMARY KEY, line INT, stop INT, CONSTRAINT fk_line FOREIGN KEY(line) REFERENCES line(id), CONSTRAINT fk_stop FOREIGN KEY(stop) REFERENCES stop(id) );
When I launch the following sentence
INSERT INTO line(id, name) VALUES (1, 'Line 1'); INSERT INTO stop(id, name) VALUES (2, 'Stop 2'); INSERT INTO line_stops_sequence(line, stop) VALUES (1,1), (1,2) ON CONFLICT ON CONSTRAINT fk_stop DO NOTHING;
constraint in ON CONFLICT clause has no associated index;
I know I’m inserting an stop id that is not included in the
stop table. The idea is that I want to ignore the
INSERTs that have conflicts. In the example it is just two items, but I’m inserting bulk data.
How can I do it without having to manually check the result of the query? Is there anyway to do it with the SQL sentence?