The query below is dynamically generated based on the number of rows that are being inserted. For each row of data, there is an additional UNION SELECT statement.
INSERT INTO account_sale
(qty, price, product_id)
SELECT $1, $2, t.id
FROM inventory_product AS t
WHERE t.ebay_sku = $3
UNION
SELECT $4, $5, t.id
FROM inventory_product AS t
WHERE t.ebay_sku = $6
...
When I try to run the query, I get the following:
error: column "qty" is of type integer but expression is of type text
The node.js page for this query:
module.exports = async function(orders) {
const pool = require('./config.js');
const client = await pool.connect();
const sql = ...
const data = [
1, 1.50, 10,
2, 4.50, 11
];
client.query(sql, data).then(res => {
...
}).catch(err => console.log(err));
}
If I remove the UNION from the query, like this:
INSERT INTO account_sale
(qty, price, product_id)
SELECT $1, $2, t.id
FROM inventory_product AS t
WHERE t.ebay_sku = $3
and remove the second item from data, there isn't any errors.
What am I missing here?
ordersdata I posted was the result of aconsole.logof the parameters right before executing the query, so it should be accurate.