'NodeJs PG query not executed as expected
I have the following, AWS lambda code inserting into a table:
let queryString = "INSERT INTO orders(order_id, channel, channel_order_id, channel_order_code, channel_merchant, merchant, min_time, max_time, delivery_expected_time, status, observations, total, sub_total, voucher_discount, delivery_tax, fk_customer_id, fk_address_id, order_contact, order_type, payment_pending, payment_prepaid, channel_merchant_id, order_timming, picker, delivered_by, delivery_obs, takeout, takeout_date_time, takeout_obs, indoor, table)VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31) RETURNING *";
const newOrder = await client.query(queryString, [order_id, channel, channel_order_id, channel_order_code, channel_merchant, merchant, min_time, max_time, delivery_expected_time, status, observations, total, sub_total, voucher_discount, delivery_tax, fk_customer_id, fk_address_id, order_contact, order_type, payment_pending, payment_prepaid, channel_merchant_id, order_timming, picker, delivered_by, delivery_obs, takeout, takeout_date_time, takeout_obs, indoor, table], (err, res) => {
if(err)console.log(res, err)
});
And then another insert in a table that has a foreign key that references an order(order_id), which should be the one being created at the first insert
I'm getting an error, on the second insert, that says that the order(order_id) does not exist. So it means that the order is not being created, the first insert is not being executed, but nothing is being caught in the console.log(err)
Now the interesting part. If I remove the table column from the first insert everything goes as expected
If I console.log(table) I get null
And the column is NotNull = False, which means that it can be null, just like as other values I'm using on the insert
Any hint on what could be happening here? Is there a limit of how many columns I can have on an insert?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
