In SQL and using postgressql this is a valid query, embedding a SELECT inside an INSERT -
INSERT INTO minute_registers_main_values (registers_id, t, v, i, w, pf, f)
(
SELECT id AS registers_id, '2015-09-01T16:34:02', 1.0, 9.1, 5.4, 1.3, 60.01
FROM registers WHERE main=TRUE AND cnt=0 AND hub_serial='ni1uiv'
);
I can insert a Foreign Key by doing a Select Lookup on the Insert without having to look up that other ID first.
In node-postgres, in order to INSERT many queries at once, I've turned to pg-format.
const register_categoriesInsert = `
INSERT INTO register_categories (register_id, category_id) VALUES %L
`;
await client.query(format(register_categoriesInsert, solar_ids.concat(main_ids).concat(all_other_ids)),[], (err, result)=>{
console.log(err);
console.log(result);
});
This allows you to insert many values at once off of one query call. Though I have my questions about pg-format -- it doesn't seem to use parameterization.
I'm trying to do both a large number of inserts and to take advantage of using SELECTS within an INSERT.
Can I do this using node-postgres?
client.query.