I am having problem to add result of pool.query to variable (With pool.query I am selecting only one value, id value, that I need to insert into other table). So far I have this but console.log gives me
Promise { < pending > }
router.get("/restaurants/add",checkNotAuthenticated, async (req, res) => {
var x = pool.query(`select delivery.id from delivery order by id desc limit 1`);
console.log(x);
/*pool.query(
`INSERT INTO new_table (newId)
VALUES ($1)`,
[x]);*/
res.redirect("/restaurants/dashboard")
});
Any help would be of great value.
You can directly use insert into .. select ..
as follows:
Insert into new_table (column_name)
select delivery.id from delivery order by id desc limit 1