I'm currently working with PostgresSQL 13.3 and I thought I could have a file with something like this:
INSERT INTO points (zone_id, element_id, position_id) VALUES
(SELECT zones._id, elements._id, positions._id FROM zones, elements, positions WHERE zones.name = 'A' AND elements.name = 'abc' AND positions.name = 'xyz'),
(SELECT zones._id, elements._id, positions._id FROM zones, elements, positions WHERE zones.name = 'B' AND elements.name = 'bcd' AND positions.name = 'yza');
That doesn't work but I can bulk-insert using:
INSERT INTO points (zone_id, element_id, position_id) SELECT zones._id, elements._id, positions._id FROM zones, elements, positions WHERE zones.name = 'A' AND elements.name = 'abc' AND positions.name = 'xyz';
INSERT INTO points (zone_id, element_id, position_id) SELECT zones._id, elements._id, positions._id FROM zones, elements, positions WHERE zones.name = 'B' AND elements.name = 'bcd' AND positions.name = 'yza';
I have a little more than 20,000 records and instead of executing thousands of sequential INSERTs each containing one SELECT, I was wondering if there was a way to execute a single INSERT containing all those SELECTs?
One thing that bothers me with on INSERT per SELECT is that I'm currently seeing the result of each INSERT independantly and if I do a SELECT COUNT(*) FROM points;
at the end of the execution, I notice I'm missing one row in the database and I have no idea which one it is.